日期:2014-05-18  浏览次数:20457 次

[马上给分]这句SQL语句该怎么写?
Sql中的多个判断语句怎么才能用union   all连接呢?

if   DayState=0   and   HolidayID <> 0
begin
select   *,HolidayID   as   BoundField
from   UserState
where   DepartName=@DepartName
end
else   if   HolidayID=0
begin
select   *,DayState   as   BoundField
from   UserState
where   DepartName=@DepartName  
end

union   all  

if   DayState=0   and   HolidayID <> 0
begin
select   *,HolidayID   as   BoundField
from   UserState
where   DepartName=@DepartName
end
else   if   HolidayID=0
begin
select   *,DayState   as   BoundField
from   UserState
where   DepartName=@DepartName  
end

------解决方案--------------------
if DayState=0 and HolidayID <> 0
begin
select *,HolidayID as BoundField
from UserState
where DepartName=@DepartName
union all
select *,HolidayID as BoundField
from 另外一表
where DepartName=@DepartName
end
else if HolidayID=0
begin
select *,DayState as BoundField
from UserState
where DepartName=@DepartName
union all
select *,DayState as BoundField
from 另外一表
where DepartName=@DepartName
end

------解决方案--------------------
if DayState=0 and HolidayID <> 0
begin
select *,HolidayID as BoundField
from UserState
where DepartName=@DepartName
end
else if HolidayID=0
begin
select *,DayState as BoundField
from UserState
where DepartName=@DepartName
end
------解决方案--------------------
那把每次所查询出来的结果都放在一个临时表里,最后再做查询呢?