如何在下面的查询中处理null。 [英] How to handle null in below query.

查看:69
本文介绍了如何在下面的查询中处理null。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在下面的查询中处理null。

How to handle null in below query.




选择USERID,

当SignDay = 01然后AttStatus结束'01', - CHECKIN每一天

当SignDay = 02然后AttStatus结束'02',

的情况,当SignDay = 03然后AttStatus结束'03',

情况当SignDay = 04然后AttStatus结束'04',

情况当SignDay = 05然后AttStatus结束'05'
来自vwAttInOut的


其中userid = 11且年份(signdate)= 2015年和月份(signdate)= 08



我尝试了什么:



我尝试过使用CTE,加入但是仍然没有找到办法处理null


select USERID,
case when SignDay = 01 then AttStatus end '01', -- CHECKIN EACH DAY
case when SignDay = 02 then AttStatus end '02',
case when SignDay = 03 then AttStatus end '03',
case when SignDay = 04 then AttStatus end '04',
case when SignDay = 05 then AttStatus end '05'
from vwAttInOut
where userid=11 and year(signdate)=2015 and month(signdate)=08

What I have tried:

I tried using CTE, Joins but still didn't find any way to handle null

推荐答案

select USERID,
CASE ISNULL(USERID, 'NULLVALUE')
case when SignDay = 01 then AttStatus end '01', -- CHECKIN EACH DAY
case when SignDay = 02 then AttStatus end '02',
case when SignDay = 03 then AttStatus end '03',
case when SignDay = 04 then AttStatus end '04',
case when SignDay = 05 then AttStatus end '05'
when 'NULLVALUE' then 'USERID'
else 'USERID'
end
from vwAttInOut
where userid=11 and year(signdate)=2015 and month(signdate)=08





希望这能解决您的问题。



Hope this will solves your problem.


您好,



以下解决方案为您提供全程帮助,请进一步说明在这里回复。





Hi,

Below solution is help full for you, any further clarification please reply here.


select USERID,
 case when SignDay = 01 then AttStatus end '01', -- CHECKIN EACH DAY
 case when SignDay = 02 then AttStatus end '02',
 case when SignDay = 03 then AttStatus end '03',
 case when SignDay = 04 then AttStatus end '04',
 case when SignDay = 05 then AttStatus end '05',
 case when SignDay IS NULL then AttStatus end 'No Day',
 case when SignDay = '' then AttStatus end 'No Day'
 from vwAttInOut
 where userid=11 and year(signdate)=2015 and month(signdate)=08


这篇关于如何在下面的查询中处理null。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆