CASE vs. IF/ELSE in T-SQL ISNULL

  • I am truncated with some T-SQL statements.

    The objective is to check for an empty string AND a Null value within a specific column of data in a row.

    Take my example below:

    CREATE PROCEDURE getIDs

    @globalID varChar(50)

    SELECT DISTINCT ISNULL(1stID, 2ndID) theID

    FROM dbo.tableName

    WHERE globalID = @globalID

    -- What I have here is code that check to see if the 1stID is Null and if so, check the 2ndID and call it 'theID'...

    -- What I need now is to also check to see if the 1stID or 2ndID returns empty or nothing in the column, in addition to NULL

    I was pondering on using CASE statements then also IF/Else... but obviously became truncated.:w00t:

    any ideas? examples?

  • IF / ELSE is conditional processing of statements, so CASE would better match your requirements.

    You will need to provide a more complete explanation of conditions and outcomes for a viable solution.

    [theID] = CASE

    WHEN 1stID IS NULL AND ... THEN ...

    WHEN 1stID = '' THEN ...

    WHEN 2ndID IS NULL THEN ...

    WHEN 2ndID = '' THEN ...

    ELSE ... END


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • turns out CASE worked...I knew not its use and correct syntax.

    thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply