7

This seems like a simple question, but I haven't been able to find an answer. I am basically trying to do this:

SELECT * FROM table1
IF(columnA > 0) BEGIN
columnB = 'Greater than 0'
END

I don't want the value to change in the table, I just want it to change in the result. ANy suggestions?

Tyler Mortensen
  • 451
  • 3
  • 8
  • 19

2 Answers2

26
SELECT  ColumnA
        , case when ColumnA > 0 then 'Greater than 0' else ColumnB END AS ColumnB 
FROM    table1;
Kevin Suchlicki
  • 3,096
  • 2
  • 15
  • 17
7

This should work:

SELECT columnA, IIF(columnA > 0, 'Greater than 0', columnB)
  FROM table1;
vlad
  • 4,748
  • 2
  • 30
  • 36
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521