当前位置: 代码迷 >> Sql Server >> 条件判断Sql
  详细解决方案

条件判断Sql

热度:102   发布时间:2016-04-27 20:36:21.0
条件判断Sql求助
如何在sql语句中用判断,
比如当前时间小于某值,select   a   as   hhh,
大于某值,select   b   as   hhh,
写到一个select中,怎么写

------解决方案--------------------
select hhh=case when dt <getdate() then 'a '
else 'b ' end from t
------解决方案--------------------
select (case when getdate() < '2007-1-1 ' then a when getdate()> '2007-7-7 ' then b end) as hhh
from table
------解决方案--------------------
case
------解决方案--------------------
select 'a ' , 'hhh '= case when getdate() < dt then (select a as hhh) else (select b as hhh) end
from table
  相关解决方案