Using a case statement to compare to a paremeter.

  • Everything worked great until i added this snippet.

    I want a column that tells me what "ID" matched a parameter value.

    When i run this, I get: An item with the same key has already been added error

    ,CASE 
    WHEN T.[PD_ID] in (@Part)
    THEN 'PD_ID_Match'
    WHEN T.[Flat_PD_ID] in (@Part)
    THEN 'FLAT_PD_ID_Match'
    WHEN T.[Like_PD_ID] in (@Part)
    THEN 'Like_PD_ID_Match'
    WHEN T.[Flat_Like_PD_ID] in (@Part)
    THEN 'Flat_Like_PD_ID_Match'
    END as Field_Match

    Thoughts? thanks

  • Note: this works in SSMS, but crashes in SSRS.

  • Maybe try CASTing to an explicit length?:

    ,CASE 
    WHEN T.[PD_ID] in (@Part)
    THEN CAST('PD_ID_Match' AS varchar(30))
    WHEN T.[Flat_PD_ID] in (@Part)
    THEN CAST('FLAT_PD_ID_Match' AS varchar(30))
    WHEN T.[Like_PD_ID] in (@Part)
    THEN CAST('Like_PD_ID_Match' AS varchar(30))
    WHEN T.[Flat_Like_PD_ID] in (@Part)
    THEN CAST('Flat_Like_PD_ID_Match' AS varchar(30))
    END as Field_Match

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

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

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