I have a select statement which will return 2 columns.
ID | IDParent
Then in my program I have to test if IDParent is < 1 then use
if IDParent is < 1 then use
sql server 2012
with student as (select sid,year from ( values (101,5),(102,5),(103,4),(104,3),(105,2),(106,1),(107,4) ) as student(sid,year) ) select iif(year=5,sid,year) as myCol,* from student myCol sid year 101 101 5 102 102 5 4 103 4 3 104 3 2 105 2 1 106 1 4 107 4