Nulls in SQL Visual Studio 2008

Posted on 2009-02-08
Last Modified: 2013-11-26

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



	SELECT name = (name + secondName + ' (' + ')'), locationID FROM locations


Open in new window

Question by:davecocks
    LVL 5

    Accepted Solution

    SELECT name = (name + ISNULL(secondName,'') + ' (' + ')'), locationID FROM locations
    LVL 27

    Expert Comment

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

    Expert Comment

    COALESCE returns NULL if all arguments are NULL so  COALESCE(secondName) would still return null if secondName is null.
    LVL 27

    Expert Comment

    you're right..

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

    Author Closing Comment

    Thanks sampipes, worked perfect!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now