?
Solved

Nulls in SQL Visual Studio 2008

Posted on 2009-02-08
5
Medium Priority
?
203 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:davecocks
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
sampipes earned 2000 total points
ID: 23584554
SELECT name = (name + ISNULL(secondName,'') + ' (' + ')'), locationID FROM locations
 
0
 
LVL 27

Expert Comment

by:nmarun
ID: 23584635
SELECT name = (COALESCE(name) + COALESCE(secondName) + ' (' + ')'), locationID FROM locations
0
 
LVL 5

Expert Comment

by:sampipes
ID: 23584680
COALESCE returns NULL if all arguments are NULL so  COALESCE(secondName) would still return null if secondName is null.
0
 
LVL 27

Expert Comment

by:nmarun
ID: 23584721
you're right..

SELECT name = (COALESCE(name, '') + COALESCE(secondName, '') + ' (' + ')'), locationID FROM locations
0
 
LVL 1

Author Closing Comment

by:davecocks
ID: 31544248
Thanks sampipes, worked perfect!!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question