Union的问题
declare @count int
Select @count=count(*) From Table1 Where id= '1 ' and Name= 'A '
if @count> 0
begin
-- Insert into @table
Select 'A ', 'AA '
end
union
Select @count=count(*) From table2 Where id= '1 ' and Name= 'B '
if @count> 0
begin
-- Insert into @table
Select 'B ', 'BB '
end
怎么把生成结果集为
A | AA
B | BB
------解决方案------------------------看你的意思这样就可以了
Select 'A ', 'AA ' From Table1 Where Exists(Select 1 From Table1 Where id= '1 ' and Name= 'A ')
Union
Select 'B ', 'BB ' From Table2 Where Exists(Select 1 From Table2 Where id= '1 ' and Name= 'B ')