当前位置: 代码迷 >> Sql Server >> [马上给分]这句SQL语句该如何写
  详细解决方案

[马上给分]这句SQL语句该如何写

热度:2   发布时间:2016-04-27 16:05:00.0
[马上给分]这句SQL语句该怎么写?
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
------解决方案--------------------
那把每次所查询出来的结果都放在一个临时表里,最后再做查询呢?
  相关解决方案