Click here to Skip to main content
15,892,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
i have below table like this.
id name class
1 A null
2 B null
3 c null
4 d null
1 A 9
3 c 9

how to check data with bit value is exist or not. i need below output.

id name class exist
1 A null 0
2 B null 0
3 c null 0
4 d null 0
1 A 9 1
3 c 9 1

regards
Kishore

What I have tried:

SELECT  Id,name,class
(case when isnull(class,123)=123 then 0 else 1 end) as exist
FROM                                 test_Table
Posted
Updated 28-Aug-17 5:19am

1 solution

Add a comma...
SQL
SELECT  Id,name,class
(case when isnull(class,123)=123 then 0 else 1 end) as exist
FROM                                 test_Table
Becomes:
SQL
SELECT  Id,name,class,
(case when isnull(class,123)=123 then 0 else 1 end) as exist
FROM                                 test_Table

But I'd probably do it a safer way:
SQL
SELECT  Id, Name, Class, CASE WHEN Class IS NULL THEN 0 ELSE 1 END AS Exist
FROM test_Table
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900