Nulls in SQL Visual Studio 2008

Hi,

I've got a SPROC that is returning Nulls for some records. 'name' has data in all the fields but 'secondName' is optional. I'm guessing thats why I'm getting Nulls for some records.

How best is it to deal with Nulls in this situation?

Thanks in advance,
ALTER PROCEDURE dbo.locationsListing
	
AS
	SELECT name = (name + secondName + ' (' + ')'), locationID FROM locations
 
	RETURN

Open in new window

LVL 1
davecocksAsked:
Who is Participating?
 
sampipesConnect With a Mentor Commented:
SELECT name = (name + ISNULL(secondName,'') + ' (' + ')'), locationID FROM locations
 
0
 
nmarunCommented:
SELECT name = (COALESCE(name) + COALESCE(secondName) + ' (' + ')'), locationID FROM locations
0
 
sampipesCommented:
COALESCE returns NULL if all arguments are NULL so  COALESCE(secondName) would still return null if secondName is null.
0
 
nmarunCommented:
you're right..

SELECT name = (COALESCE(name, '') + COALESCE(secondName, '') + ' (' + ')'), locationID FROM locations
0
 
davecocksAuthor Commented:
Thanks sampipes, worked perfect!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.