求一条SQL语句
select * from table1 union all select * from table2 ...
但是有可能table2不存在 所以我要判断 如果存在table2就union all 我想要这样的形式 select * from talbe1 如果table2存在就连接(union all select * from table2)不存在就只执行前边的查询
select * from table1 union all select * from table2 ...
但是有可能table2不存在 所以我要判断 如果存在table2就union all 我想要这样的形式 select * from talbe1 如果table2存在就连接(union all select * from table2)不存在就只执行前边的查询
Declare
i Varchar(50);
Begin
Select count(table_name) Into i From user_tables Where table_name = 'xtcs';
If i = 0 Then
Select * From table1l;
Else
Select * From table1 Union All Select * From table2;
End If
End;
--MSSQL
If Not Exists (Select * From sysobjects Where Name = upper('table2') And Type = 'U')
Select * From table1;
Else
Select * From table1 Union All Select * From table2;
不知道是这个意思不,谨供参考!