To case or not

Last post 11-21-2008, 4:05 PM by jtappero. 1 replies.
Sort Posts: Previous Next
  •  11-20-2008, 1:41 PM Post number 70557

    • tcstl is not online. Last active: 04-24-2009, 2:01 PM tcstl
    • Top 50 Contributor
    • Joined on 05-02-2007
    • Level 2: Deep Blue

    To case or not

    I have a sql statement which needs to be modified.  It combines several fields or any combination  may or may not be null.  I need one space between each value when it exists.  I was wondering if using case for this might be the best approach.

    select action,quantity,
    Ltrim((isnull(ACTION,'')+  ' '+ isnull(QUANTITY,'') + ' '+ isnull(UNITOFMEASURE,'') +
    ' ' + isnull(ROUTE,'') + ' ' + isnull(FREQUENCY,'') + ' ' + isnull(SYMPTOM,'') + ' ' + isnull(ADDITIONALSIGNETUR,''))) as sig

    from medicationorder
  •  11-21-2008, 4:05 PM Post number 70571 in reply to post number 70557

    • jtappero is not online. Last active: 12-03-2008, 11:46 AM jtappero
    • Top 200 Contributor
    • Joined on 10-20-2006
    • Big Bear Lake, CA USA
    • Level 1: Deep thought

    Re: To case or not

    No need.  Since concatenating a NULL to another string simply results in NULL, which you can then still use as the expression to test for the isnull function, you can simplify this whole thing like so...

    select action,quantity,
    Ltrim((isnull(ACTION+' ','') + isnull(QUANTITY+' ','') + ...

View as RSS news feed in XML