Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get the column value that is null but i am not able to do so.

What I have tried:

I have below query and it is giving all results including Null as well. But i need to filter on the basis of commented segmentIDs and i need null value as well. Don't require the Segments else than below filter(Commented Currently)

SQL
Select distinct SegmentID,Sum(distance) as TotalDistance from [dbo].[tblBookingContent] 
where Orgnization = 'REGERINGSKANSLIET' --and segmentid in ('LUX001S02','LUX001S11','SWE001S03','SWE001S09','SWE001S14','SWE001S20','SWE001S15','SWE001S23')
and IsV4 in (0,1) 
and departuredate between 
convert(datetime, '2016-07-01', 110) and 
convert(datetime, '2016-09-30', 110) and MPSS= 1
and BookingNumber not in (select BookingNumber from tblBookingContent where BookingStatus=1)
group by SegmentId



SegmentID | Distance
========== | =========
NULL | 28088.9700
SWE001S02 | 125.0990
SWE001S03 | 9295.0810
SWE001S06 | 710.4410
SWE001S09 | 15510.0310
SWE001S11 | 733.4110

Expected Result
===============

SegmentID | Distance
========== | =========
NULL | 28088.9700
SWE001S03 | 9295.0810
SWE001S09 | 15510.0310
Posted
Updated 29-Nov-16 21:25pm

1 solution

It seems easy, I'm not sure to understand weel but try this:

C#
Select distinct SegmentID,Sum(distance) as TotalDistance from [dbo].[tblBookingContent] 
where Orgnization = 'REGERINGSKANSLIET' 
and (segmentid is null or segmentid in ('LUX001S02','LUX001S11','SWE001S03','SWE001S09','SWE001S14','SWE001S20','SWE001S15','SWE001S23'))
and IsV4 in (0,1) 
and departuredate between 
convert(datetime, '2016-07-01', 110) and 
convert(datetime, '2016-09-30', 110) and MPSS= 1
and BookingNumber not in (select BookingNumber from tblBookingContent where BookingStatus=1)
group by SegmentId
 
Share this answer
 

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