Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)


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
Posted

1 solution

Hi,
Check the following Query... use OR Operator for this simple checking.
SQL
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)

Regards,
GVPrabu
 
Share this answer
 
v2
Comments
dhage.prashant01 9-May-13 6:35am    
This works fine, but when i put and MPD.MPD_MRFStatusID = 5 (open state) in where clause
it gives me all records including null but MPD_MRFStatusID = 5 does not work
gvprabu 9-May-13 6:42am    
Check now I updated my solution
dhage.prashant01 9-May-13 6:45am    
(MPD.MPD_DemandStatus = @RRPTDemandStatus OR @RRPTDemandStatus is null) worked for me

btw what does below condition mean?
@RRPTDemandStatus is null
gvprabu 9-May-13 6:48am    
See When ever @RRPTDemandStatus variable contains any value then only it will check the table values else it will return all records from ur table.
gvprabu 9-May-13 6:50am    
See if u pass any values for @RRPTDemandStatus variable then u need only those details else u want to list all records right(Else case U will pass NULL for @RRPTDemandStatus variable) right. then this is correct, check and confirm or tel me whts your actual requirement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900