How do I embed an IF statement within a SELECT statement?
I want to select values from a table using a view or stored procedure but one of the columns values must be based on the value of another column
e.g.
col1 col2 col3
1 10 12
2 15 13
3 20 14
4 25 15
SELECT col1,col2,
if col3 > 13
val='LargeVal'
else
val = 'SmallVal' as Calculated Column
I want the output to be
col1 col2 Calculated Column
1 10 SmallVal
2 15 SmallVal
3 20 LargeVal
4 25 LargeVal
i.e. Calulated column is a derived column. In MSAccess I was able to use the IIF function but SQL Server does not seem to recognise it even though the Books Online documents it.
Your help is appreciated.
I want to select values from a table using a view or stored procedure but one of the columns values must be based on the value of another column
e.g.
col1 col2 col3
1 10 12
2 15 13
3 20 14
4 25 15
SELECT col1,col2,
if col3 > 13
val='LargeVal'
else
val = 'SmallVal' as Calculated Column
I want the output to be
col1 col2 Calculated Column
1 10 SmallVal
2 15 SmallVal
3 20 LargeVal
4 25 LargeVal
i.e. Calulated column is a derived column. In MSAccess I was able to use the IIF function but SQL Server does not seem to recognise it even though the Books Online documents it.
Your help is appreciated.