Mhmt
Mhmt

Reputation: 769

How to use if statement in SQL Query?

 Select Value1,Value2,Value3 from Table1 where time > DATEADD(DAY,-2,GETDATE())

 ordery BY time desc

Result :

Value1=25

Value2=50

Value3=70

How can I change result to be

Value1=25

Value2=0 (if Value2=50 it will be 0)

Value3=70

Upvotes: 1

Views: 82

Answers (1)

John Woo
John Woo

Reputation: 263933

If I understand you correctly, you can use CASE statement,

SELECT Value1,
       CASE WHEN Value2 = 50 THEN 0 ELSE Value2 END Value2,
       .....

Upvotes: 4

Related Questions