December 3, 2013 at 4:37 am
SELECT
C.containerCode + ':' + C.containerName as display,
C.containerCode AS code
FROM Containers C
INNER JOIN ContainersTypes CT ON
CT.containerTypeSqlId = C.containerTypeSqlId AND
CT.containerTypeIncId = C.containerTypeIncId
WHEREC.isDeleted = 0
ORDER BY display
Hi
I have a query like this for populating a report parameter combo box in my SRRS report. But when the
C.containerName in the ‘display’ column is NULL, the ‘display’ column returns a NULL value.
Also the ‘display’column values with NULL will come first in the result set instead of the result ordering by display column.
How can I avoid this?
December 3, 2013 at 5:01 am
December 3, 2013 at 5:32 am
First question to pose is: Shoud that column have nulls ?
Second question to pose is: wouldn't a default empty varchar do the same trick ? If so modify the data model so the column is Not-Nullable and put an empty string in all occurences that are nulled.
If you cannot avoid NULLs, your applications will have to deal with that every time !
your TSQL options are
Isnull( yourcolumn, 'replacementvalue' )
Isnull( yourcolumn, othercolumn ) -- <-- may still return NULL if othercolumn is also nullable
Coalesce( yourcolumn, othercolumn, ..., 'replacementvalue')
check books online for details !
When using concatenation, keep in mind you also need to translate the columns to a common data type.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
December 5, 2013 at 2:40 am
Thanks everyone for the replies..
I changed my script like this:
SELECT
ISNULL(C.containerCode, '') + ':' + ISNULL(C.containerName, '') as display,
C.containerCode AS code
FROM Containers C
INNER JOIN ContainersTypes CT ON
CT.containerTypeSqlId = C.containerTypeSqlId AND
CT.containerTypeIncId = C.containerTypeIncId
WHEREC.isDeleted = 0
ORDER BY display
January 21, 2014 at 7:59 pm
---- will return zzz for null and blank values if your data is varchar it will send it to the bottom of the list change to numerical values if that is more feasible
--- of course you can change zzz to any value that works for you and it keeps the fields from being blank I know this post is over a month old but thought it may help someone else
SELECT
isnull(nullif(C.containerCode,''),'zzz') + ':' + isnull(nullif(C.containerName,''),'zzz') as display,
C.containerCode AS code
FROM Containers C
INNER JOIN ContainersTypes CT ON
CT.containerTypeSqlId = C.containerTypeSqlId AND
CT.containerTypeIncId = C.containerTypeIncId
WHEREC.isDeleted = 0
ORDER BY display
January 23, 2014 at 3:11 am
Thanks for the post. Nullif is new to me.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply