using access query into sql view HELP!

  • Hi, I'm trying to use the query in sql

    how do i do this.

    I want to represent the words ie. Long term

    SELECT IIf([CurrentSickTerm]="LT","Long Term","Short Term") AS SickTerm

    Thanks

  • There is no immediate if statement in TSQL. You'll need to create some other mechanism, probably a CASE statement to get the same effect.

    SELECT CASE WHEN CurrentSickTerm= 'LT'

    THEN 'Long Term'

    ELSE 'Short Term' END AS ColumnName

    FROM dbo.ViewName

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • this works but i need to add another condition !

    SELECT CASE WHEN CurrentSickTerm= 'LT'THEN 'Long Term' ELSE if CurrentSickTerm= 'ST'THEN 'Short Term' else 'NULL' END AS ColumnNameFROM dbo.ViewName

    This does not work I need another way to write this

    Thanks Ritz

  • Check BOl for the CASE syntax. Try:

    SELECT

    CASE CurrentSickTerm

    WHEN 'LT' THEN 'Long Term'

    WHEN 'ST' THEN 'Short Term'

    WHEN 'MT' THEN 'Medium Term'

    ELSE 'Healthy'

    END AS SickTerm

    FROM dbo.ViewName

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

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