1
 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

1 Answer 1

4

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

SELECT Value1,
       CASE WHEN Value2 = 50 THEN 0 ELSE Value2 END Value2,
       .....
Sign up to request clarification or add additional context in comments.

2 Comments

@ 今 草 顿 웃 Executing query time : 00:00:04 for using my first query. But when I used this query Executing query time : 00:01:04.Is it normal ?
Mehmet your query is now having to evaluate data in the column value2 to determine which value to output from the CASE statement. So it's going to require further processing, causing execution time to increase.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.