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

这种语句有什么办法简写?
SQL code

select (case when [员工编号] in ('634','3283','3332') then 5 end ) from #AT
想在case加一个判断如果员工的进厂时间大于15号就返回NULL,在15号前进厂的返回5,这样的要怎么写才好



------解决方案--------------------
可以用union all 

select 5,* from tb where 15号之前
union all
select null,* from tb where 大于15号
------解决方案--------------------
select (case when [员工编号] in ('634','3283','3332') and day(时间) < 15 then 5 else null end ) from #AT

------解决方案--------------------
select case when 进厂时间>15 then null else 5 end as ... from tbl where [员工编号] in ('634','3283','3332')