如果参数为null,如何获取所有记录 [英] How to get all records if parameter is null

查看:63
本文介绍了如果参数为null,如何获取所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

我有2张桌子

1. RPT_MRFProgressDetails

2. MasterData



RPT_MRFProgressDetails有列MPD_DemandStatus,它有值和空值



我试过以下:

Hi friends,
I have 2 tables
1. RPT_MRFProgressDetails
2. MasterData

RPT_MRFProgressDetails has column MPD_DemandStatus which has values as well as null value

I tried following:

Declare @RRPTDemandStatus char(7) = null
select mpd.MPD_DemandStatus, m.Description,* from RPT_MRFProgressDetails mpd
left outer join MasterData M on mpd.MPD_DemandStatus = M.Id
where mpd.MPD_DemandStatus = ISNULL(@RRPTDemandStatus, mpd.MPD_DemandStatus)





上面的查询给出了在MPD_DemandStatus列中有值的记录,空值被忽略。



我想要来自RPT_MRFProgressDetails的所有记录,包括具有空值的MPD_DemandStatus列。



任何想法怎么办?



感谢avdance



Above query gives me records which has value in MPD_DemandStatus column, Null values are ignored.

I want all records from RPT_MRFProgressDetails including MPD_DemandStatus column having null values.

Any idea how to do??

Thanks in avdance

推荐答案



检查以下查询...使用OR运算符这个简单的检查。

Hi,
Check the following Query... use OR Operator for this simple checking.
Declare @RRPTDemandStatus char(7) = null
select mpd.MPD_DemandStatus, m.Description,* from RPT_MRFProgressDetails mpd
left outer join MasterData M on mpd.MPD_DemandStatus = M.Id
where ((mpd.MPD_DemandStatus = @RRPTDemandStatus AND @RRPTDemandStatus IS NOT NULL) OR @RRPTDemandStatus IS NULL)



问候,

GVPrabu


Regards,
GVPrabu


这篇关于如果参数为null,如何获取所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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