Case checking 2 different values - 2 different fields

  • Hello Experts,

    Im having problem writing this logic,

    I need to compare 2 fields in a case statement
    First Value is sola.License
    Second Value sola.LicenseNumber

    If the LicenseNumber is null, I need to take the value of the License.
    If the LicenseNumber is not null then I need to concatenate License + LicenseNumber

    How can I do that? Here is my logic but is not working

    case when sola.License is not null

           then 
                 (when sola.LicenseNumber is null
                     
    then 'LicenseNumber Missing' else sola.License + ' ' + sola.LicenseNumber)

           when soll.Comment is not null
          
    then soll.Comment
          
    else 'Missing'
    end AS License,

    I need to keep the other logic for the License also, any help will be appreciate it!!

  • ISNULL(License + ' ' + LicenseNumber,License)

  • Well the result you asked for doesn't match the pseudo code at all, what gilbert posted will get you the results you asked for.

    But if you want to clean up your pseudo code,

    case when sola.License is not null AND sola.LicenseNumber is null THEN 'LicenseNumber Missing'
    WHEN sola.License is not null AND sola.LicenseNumber is NOT null THEN sola.License + ' ' + sola.LicenseNumber
    when soll.Comment is not null then soll.Comment 
    ELSE 'Missing'
    END AS License

  • Thank you so much!!

    This works!!!!!!

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

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