Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL SELECT If (a="") Then change b value

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?

like image 642
Tyler Mortensen Avatar asked Apr 22 '13 19:04

Tyler Mortensen


2 Answers

SELECT  ColumnA
        , case when ColumnA > 0 then 'Greater than 0' else ColumnB END AS ColumnB 
FROM    table1;
like image 80
Kevin Suchlicki Avatar answered Nov 02 '22 21:11

Kevin Suchlicki


This should work:

SELECT columnA, IIF(columnA > 0, 'Greater than 0', columnB)
  FROM table1;
like image 43
Ted Hopp Avatar answered Nov 02 '22 20:11

Ted Hopp