Alternative NULL values

Source:
col1 col2
1 Will
2 John
3 Josh
4 Devin
Target:
col1 col2
1 Will
2 NULL
3 John
4 NULL
5 Josh
6 NULL
7 Devin
8 NULL
I want the SQL query for the above scenario ?

Showing Answers 1 - 6 of 6 Answers

Rakesh

  • Mar 2nd, 2017
 

SELECT COL1, CASE
WHEN MOD(COL1,2) = 0 THEN NULL
ELSE
COL2
END CASE
FROM G2

  Was this answer useful?  Yes

SANTHOSH KUMAR GUJJA

  • Nov 25th, 2017
 

SEL CASE WHEN COL1=1 THEN COL1 ELSE COL1+MIN(COL1) OVER(ORDER BY COL1 ASC ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) END AS
COL1,COL2 FROM TABLE
UNION
SEL COL1,NULL AS COL2 FROM TABLE WHERE COL1<>1

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions