Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: When then syntax

    Previos post didtn work here is my code:

    (id and usd are columns)

    SELECT Name, Rating ,
    CASE
    WHEN ID ='F' THEN USD/10000 END AS 'Exposure',
    WHEN ID ='O' THEN USD/10000 END AS 'Exposure 0,
    WHEN ID ='R' THEN USD/10000 END AS 'Exposure R',
    END,
    Industry,
    FROM myTable


    i am getting error: 'Msg 156, Level 15, State 1, Line 4
    Incorrect syntax near the keyword 'AS'.'

  2. #2
    Join Date
    Aug 2004
    Location
    Berlin, Germany
    Posts
    12
    For Each Colm only one name

    SELECT Name, Rating ,
    CASE
    WHEN ID ='F' THEN USD/10000 END
    WHEN ID ='O' THEN USD/10000 END
    WHEN ID ='R' THEN USD/10000 END
    END AS ColmNm,
    Industry
    FROM myTable

    L.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT Name
         , Rating 
         , CASE WHEN ID ='F' THEN USD/10000 END AS 'Exposure'
         , CASE WHEN ID ='O' THEN USD/10000 END AS 'Exposure 0'
         , CASE WHEN ID ='R' THEN USD/10000 END AS 'Exposure R'
         , Industry 
      FROM myTable

    lento, it's column, not "colm"

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    Quote Originally Posted by r937
    Code:
    SELECT Name
         , Rating 
         , CASE WHEN ID ='F' THEN USD/10000 END AS 'Exposure'
         , CASE WHEN ID ='O' THEN USD/10000 END AS 'Exposure 0'
         , CASE WHEN ID ='R' THEN USD/10000 END AS 'Exposure R'
         , Industry 
      FROM myTable

    lento, it's column, not "colm"

    Maybe the column is Irish, in that case it is Colm.

  5. #5
    Join Date
    Aug 2004
    Location
    Berlin, Germany
    Posts
    12
    Are there now 3 column and 1 colm?

  6. #6
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580

    Question Question

    Not sure of the purpose of this case statement but:-

    SELECT
    Name, Rating, Industry, USD / 10000 AS USDValue,
    CASE ID
    WHEN 'F' THEN 'Exposure'
    WHEN 'O' THEN 'Exposure 0'
    WHEN 'R' THEN 'Exposure R'
    END AS ExposureType
    FROM dbo.tblDbforum

    Will return a different descriptive 'ExposureType' for each row depending on the value of ID for that row.

    Dont know why you have the USD within the case statement as it is the same each time - USD / 10000 is it not?

    If this is not what you are trying to acheive, then please post some sample data and your required results.
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •