Nested Searched Case statement

  • I have the following statement that worked until I tried to nest it with the above CASE WHEN (SELECT ST_Percent FROM Royalties.dbo.tblStockMain WHERE ST_Code = @StockCode) IS NULL

    I get an error ..Incorrect syntax near the keyword 'As', Incorrect syntax near the keyword 'SUM'

    Here's the code

    CASE WHEN (SELECT ST_Percent FROM Royalties.dbo.tblStockMain WHERE ST_Code = @StockCode) IS NULL

    THEN

    CASE WHEN (SELECT ST_CalcPrice FROM Royalties.dbo.tblStockMain WHERE ST_Code = @StockCode) <

    ((SUM(CASE SM_Status

    WHEN 'I' THEN (DET_NETT * -1 )

    ELSE DET_NETT

    END) * 74) / 100) /

    SUM(CASE SM_Status

    WHEN 'I' THEN (SM_Quantity * -1)

    ELSE SM_Quantity

    END)

    THEN

    ((( SUM(CASE SM_Status

    WHEN 'I' THEN (DET_NETT * -1 )

    ELSE DET_NETT

    END) * 74) / 100)/

    SUM(CASE SM_Status

    WHEN 'I' THEN (SM_Quantity * -1)

    ELSE SM_Quantity

    END) * 10) / 100

    ELSE

    (((SUM(CASE SM_Status

    WHEN 'I' THEN (DET_NETT * -1 )

    ELSE DET_NETT

    END) * 74) / 100) /

    SUM(CASE SM_Status

    WHEN 'I' THEN (SM_Quantity * -1)

    ELSE SM_Quantity

    END) * 5) / 100

    END AS Royality

    ELSE

    (((SUM(CASE SM_Status

    WHEN 'I' THEN (DET_NETT * -1 )

    ELSE DET_NETT

    END) * 74) / 100) /

    SUM(CASE SM_Status

    WHEN 'I' THEN (SM_Quantity * -1)

    ELSE SM_Quantity

    END) * 25) / 100

    END AS Royality

    any help why would be brillant. Like I say works fine with the main body but as i enter the condition about IS NULL then i get this error.

    Thanks

    Scott

  • sorry..the formatting has gone...not very readable

  • I have solved the problem...

    I had placed 2 'AS Royality' in the query.

    Scott

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

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