Facng Problem In CASE

  • [font="Arial"]Hi all

    I am facing some problem in the following please tell me that what is wrong.[/font]

    DECLARE @TableName nvarchar(Max),@Abbreviation nvarchar(100)

    SET @Abbreviation='HH'

    select CASE @Abbreviation

    WHEN 'HH' THEN SET @TableName='Hotel_History'

    WHEN 'HA' THEN SET @TableName='Hotel_Accomodation'

    WHEN 'HD' THEN SET @TableName='Hotel_Dining'

    WHEN 'HB' THEN SET @TableName='Hotel_Banquet_Conference'

    WHEN 'HF' THEN SET @TableName='Hotel_Facilities_Services'

    WHEN 'HV' THEN SET @TableName='Hotel_Virtual_Tour'

    WHEN 'HG' THEN SET @TableName='Hotel_Gallery'

    ELSE SET @TableName='NotMatch'

    END

    PRINT @TableName

    Thanks

    Warm Regards,
    Shakti Singh Dulawat
    Before printing, think about the environment
    Do the impossible, and go home early.

  • Remove the SET= from the case as below ...

    DECLARE @TableName nvarchar(Max),@Abbreviation nvarchar(100)

    SET @Abbreviation='HH'

    SELECT

    @TableName =

    CASE @Abbreviation

    WHEN 'HH' THEN 'Hotel_History'

    WHEN 'HA' THEN 'Hotel_Accomodation'

    WHEN 'HD' THEN 'Hotel_Dining'

    WHEN 'HB' THEN 'Hotel_Banquet_Conference'

    WHEN 'HF' THEN 'Hotel_Facilities_Services'

    WHEN 'HV' THEN 'Hotel_Virtual_Tour'

    WHEN 'HG' THEN 'Hotel_Gallery'

    ELSE 'NotMatch'

    END

    PRINT @TableName

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Use:

    DECLARE @TableName nvarchar(Max),@Abbreviation nvarchar(100)

    SET @Abbreviation='HH'

    select @TableName = CASE @Abbreviation

    WHEN 'HH' THEN 'Hotel_History'

    WHEN 'HA' THEN 'Hotel_Accomodation'

    WHEN 'HD' THEN 'Hotel_Dining'

    WHEN 'HB' THEN 'Hotel_Banquet_Conference'

    WHEN 'HF' THEN 'Hotel_Facilities_Services'

    WHEN 'HV' THEN 'Hotel_Virtual_Tour'

    WHEN 'HG' THEN 'Hotel_Gallery'

    ELSE 'NotMatch'

    END

    PRINT @TableName

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Hmmm, Jason managed to post his response between me refreshing to see if someone answered, and pasting my answer in. Witchcraft? 🙂

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Nothing magical here, I'm just looking over your shoulder Andras. 😉

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Thanks you both

    Warm Regards,
    Shakti Singh Dulawat
    Before printing, think about the environment
    Do the impossible, and go home early.

  • Great minds think alike... and, frequently, at the same time. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

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