Covert in Case

  • Hi,

    I have the following part in my Select statement -

    Select CASE WHEN dbo.[IH_RE-TNCY-PERSON].[ON-TNCY] = '1'

    THEN 'yes'

    ELSE dbo.[IH_RE-TNCY-PERSON].[ON-TNCY] END AS 'on-tncy',

    I get the error - Conversion failed when converting the varchar value 'yes' to data type tinyint.

    Now I presume I need to convert dbo.[IH_RE-TNCY-PERSON].[ON-TNCY], but I'm unsure how to do this correctly.

    Thanks

  • Ryan Keast (11/6/2013)


    Hi,

    I have the following part in my Select statement -

    Select CASE WHEN dbo.[IH_RE-TNCY-PERSON].[ON-TNCY] = '1'

    THEN 'yes'

    ELSE dbo.[IH_RE-TNCY-PERSON].[ON-TNCY] END AS 'on-tncy',

    I get the error - Conversion failed when converting the varchar value 'yes' to data type tinyint.

    Now I presume I need to convert dbo.[IH_RE-TNCY-PERSON].[ON-TNCY], but I'm unsure how to do this correctly.

    Thanks

    Try: -

    SELECT

    CASE WHEN dbo.[IH_RE-TNCY-PERSON].[ON-TNCY] = '1' THEN 'yes' ELSE CAST(dbo.[IH_RE-TNCY-PERSON].[ON-TNCY] AS VARCHAR(3)) END AS 'on-tncy',


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thanks. Worked perfectly.

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

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