Showing posts with label consist. Show all posts
Showing posts with label consist. Show all posts

Tuesday, March 20, 2012

Query to return certain result if meet requirement

Hi,
Is there anyway to query 7 table from MSSQL , If any of the table consist of 0 then the value 0 is return. If all 7 table dont consist 0 value in the table, value 1 is return

Regards
Mandrakeooi

Quote:

Originally Posted by Mandrakeooi

Hi,
Is there anyway to query 7 table from MSSQL , If any of the table consist of 0 then the value 0 is return. If all 7 table dont consist 0 value in the table, value 1 is return

Regards
Mandrakeooi


Try

select case count(*) when 0 then 1 else 0 end
from (
select myColumn from table1 where myColumn=0
union all
select myColumn from table2 where myColumn=0
union all
...
select myColumn from table7 where myColumn=0)