Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 union of tables conditionally

Author  Topic 

svibuk
Yak Posting Veteran

62 Posts

Posted - 2013-08-03 : 05:47:03
i have a table with 5 fields
field1 ie STATUS will have values as 'd' and 'i'
if the field1 of table has both the values then only the data shld e displayed
but if the field1 has only value 'd' then no data shld be displayed
i have tried select * from #temp1 where col1='d' and col1 ='i'
but nothing gets displayed

i have given here for table1
but there are 5 tables total
and i need the result output with union all

example
select * from #5_TEMP
union all
select * from #4_TEMP
union all
select * from #3_TEMP

if all this 3 tables has STATUS 'd' and 'a' then the union will be of all 3 tables

if 4_TEMP has data of only STATUS='d' then table 4_TEMP will not be included in the union
the the union will be as

select * from #5_TEMP
union all
select * from #3_TEMP

stepson
Aged Yak Warrior

545 Posts

Posted - 2013-08-03 : 08:31:51
how is your data store in field STATUS ?
i ask because a WHERE clause , i guess, will solve your prob
where col1='d' and col1 ='i'


post some sample data please


Ce-am pe mine am si-n dulap, cand ma-mbrac zici ca ma mut
sabinWeb
Go to Top of Page
   

- Advertisement -