Sql中的多个判断语句怎么才能用union all连接呢?
if DayState=0 and HolidayID <> 0
begin
select *,HolidayID as BoundField
from UserState
where [email protected]
end
else if HolidayID=0
begin
select *,DayState as BoundField
from UserState
where [email protected]
end
union all
if DayState=0 and HolidayID <> 0
begin
select *,HolidayID as BoundField
from UserState
where [email protected]
end
else if HolidayID=0
begin
select *,DayState as BoundField
from UserState
where [email protected]
end
------解决方案--------------------
if DayState=0 and HolidayID <> 0
begin
select *,HolidayID as BoundField
from UserState
where [email protected]
union all
select *,HolidayID as BoundField
from 另外一表
where [email protected]
end
else if HolidayID=0
begin
select *,DayState as BoundField
from UserState
where [email protected]
union all
select *,DayState as BoundField
from 另外一表
where [email protected]
end
------解决方案--------------------
if DayState=0 and HolidayID <> 0
begin
select *,HolidayID as BoundField
from UserState
where [email protected]
end
else if HolidayID=0
begin
select *,DayState as BoundField
from UserState
where [email protected]
end
------解决方案--------------------
那把每次所查询出来的结果都放在一个临时表里,最后再做查询呢?