首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-03-05 
[马上给分]这句SQL语句该怎么写?Sql中的多个判断语句怎么才能用unionall连接呢?ifDayState0andHolidayID

[马上给分]这句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
[解决办法]
那把每次所查询出来的结果都放在一个临时表里,最后再做查询呢?

热点排行