表SH
字段USERID,TODAY,PCS
我想判断SH.TODAY是不是等于今天,如果是,则输出PCS,如果不是,则输出0
用CASE语句可以吗?
------解决方案--------------------
- SQL code
select USERID,PCS=(case when datediff(dd,TODAY,getdate())=0 then PCS else 0 end) from SH
------解决方案--------------------
SELECT *
,CASE WHEN CONVERT(VARCHAR(10),TODAY,120)=CONVERT(VARCHAR(10),GETDATE(),120) THEN 'pcs' ELSE '0' END
FROM SH
------解决方案--------------------
- SQL code
select userid ,case when datediff(d,today,getdate()) = 0 then pcs else 0 endfrom sh