Using same column twice with different Filter conditions

  • Hi ,

    I am trying to use same column twice with different filer conditions ,any suggestions on this will be helpfull for me.

    SELECT

    Id

    ,CASE WHEN cffit.IdentifierId = 'IIN' THEN cffit.IdentifierValue END AS 'IIN'

    ,CASE WHEN cffit.IdentifierId = 'IMS' THEN cffit.IdentifierValue END AS 'IMS'

    FROM

    dbo.clo_Identifier_TB cffit

    WHERE Id=24

    This is how I am trying ,but it is giving me null values also.

  • You didn't specify an ELSE clause, so if cffit.IdentifierId is neither IIN or IMS, you will get a NULL value.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I want these values as seprate :

    Id , IIN ,IMS

    So ,If i am using else here it is giving me blank values ,I want to use only the column with values only values :

    IDIINIMS

    24NULLNULL

    2400088NULL

    24NULL111

    24NULLNULL

    I want only

    IDIINIMS

    24 00088 111

  • Maybe it's a good idea to provide sample data when you initially ask the question.

    Check the first link in my signature on how to ask questions.

    SELECT

    Id

    ,IIN = MAX(IIN)

    ,IMS= MAX(IMS)

    FROM dbo.clo_Identifier_TB cffit

    GROUP BY Id

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Hi,

    Thanks a lot for your help , Its working with using Max and group By .

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

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