sql server - Checking availability of data in columns of table in SQL? -
iam having table testtable have few columns say
c1 | c2 | c3 | c4 'ab'| 1 | 09 | //case1 [ must return 1] | | | //case2 [ must return 0] i want check if data in table present if of columns data present want value 1 , if columns blank(no data) want value 0
can 1 help, have no idea expect condition in front of me.
you can try following query, using coalesce command:
select case when coalesce(c1,c2,c3,c4) null 0 else 1 end testtable if blank values not nulls empty strings, query can changed to:
select case when c1+c2+c3+c4 = '' 0 else 1 end testtable or, best variant, check both nulls , empty strings:
select case when coalesce(c1,'')+coalesce(c2,'')+coalesce(c3,'')+coalesce(c4,'') = '' 0 else 1 end testtable
Comments
Post a Comment