Results 1 to 6 of 6

Thread: [RESOLVED] Concating Null Values

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved [RESOLVED] Concating Null Values

    I have the following SQL Statement:

    VB Code:
    1. SELECT VEN.VENNUM, (VEN.TITLE + ' ' + VEN.FNAM + ' ' + VEN.LNAM) AS PERSON ...

    When any of the fields inside of the PERSON Field are Null it returns a Null. How can I prevent this?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Concating Null Values

    As I posted this it came to me Use the Coalesce:

    VB Code:
    1. SELECT VEN.VENNUM, LTrim(Coalesce(VEN.TITLE,'') + ' ' + Coalesce(VEN.FNAM,'') + ' ' + Coalesce(VEN.LNAM,'')) AS PERSON ...
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] Concating Null Values

    You can avoid the LTRIM's by replacing

    LTrim(Coalesce(VEN.TITLE,'') + ' '

    With

    Coalesce(VEN.TITLE+' ','') + ...

    Put the space concatenation in with the potentially NULL column in the COALESCE - so if null, no title and no space.

    We do that often.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Concating Null Values

    Quote Originally Posted by szlamany
    You can avoid the LTRIM's by replacing

    LTrim(Coalesce(VEN.TITLE,'') + ' '

    With

    Coalesce(VEN.TITLE+' ','') + ...

    Put the space concatenation in with the potentially NULL column in the COALESCE - so if null, no title and no space.

    We do that often.
    you are the man!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] Concating Null Values

    Steve I tried to rep you but:
    Attached Images Attached Images  
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] Concating Null Values

    Thanks for trying!

    Us people in the DB section never get enough travel in the forum to avoid that restriction

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width