Syntax error near AS

In SQL Transform, I have...

 

SELECT * WHERE
(CASE
WHEN (FcstName LIKE '%Fcst%' AND 'Rev Month' = 1) THEN ('Margin EV'*0.314/GM_Pct)
ELSE 'Margin EV'
END)
AS MarginEVAdj
FROM sales_pipeline

 

I'm getting a syntax error "Near AS", but can't figure out what's wrong.

Thanks!

Best Answer

  • cwolman
    cwolman Contributor
    Answer ✓

    Replace the WHERE with a comma.  The WHERE clause needs to be after the FROM

     

    Try the following:

    SELECT *,
        CASE
           WHEN (FcstName LIKE '%Fcst%' AND 'Rev Month' = 1) THEN ('Margin EV'*0.314/GM_Pct)
           ELSE 'Margin EV'
        END AS MarginEVAdj
    FROM sales_pipeline

     

     

     


    -----------------
    Chris

Answers

  • cwolman
    cwolman Contributor
    Answer ✓

    Replace the WHERE with a comma.  The WHERE clause needs to be after the FROM

     

    Try the following:

    SELECT *,
        CASE
           WHEN (FcstName LIKE '%Fcst%' AND 'Rev Month' = 1) THEN ('Margin EV'*0.314/GM_Pct)
           ELSE 'Margin EV'
        END AS MarginEVAdj
    FROM sales_pipeline

     

     

     


    -----------------
    Chris
  • Thanks! I'm learning by example and googling - I was thrown by the error message that said my problem was near "AS", so I was looking for love in all the wrong places. I appreciate the help.

  • cwolman
    cwolman Contributor

    No problem at all.  Glad I could help.  You may find this link helpful as you are learning SQL.


    -----------------
    Chris