Skip to Content

Problem with case statement

Hi,

I don't know why it doesn't work, by I can't make any sql with "case".

Example:

SELECT CASE T0.[NextNumber] WHEN 6 THEN 'AAA' ELSE 'A' FROM NNM1 T0

And the syntax error near 'FROM' appears.

I tried use another apostrophes and more, but nothing works..

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Aug 19, 2016 at 02:34 PM

    Hello Barbara,

    Try This..

    select (case when t0.NextNumber>6 then 'aaa' else 'a' end) from NNM1 t0

    Regards

    Bhanu

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 20, 2016 at 08:03 AM

    SELECT CASE T0.[NextNumber] WHEN 6 THEN 'AAA' ELSE 'A' END FROM NNM1 T0


    You missed a END for Case statement.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 22, 2016 at 05:17 AM

    Try this

    SELECT CASE When T0.[NextNumber] = 6 THEN 'AAA' ELSE 'A' END FROM NNM1 T0

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 22, 2016 at 06:09 AM

    Hi Barbara,

    You get an error because you did not include the "END" Tag of your case statement. Try the code below.

    SELECT CASE WHEN NextNumber = 6 THEN 'AAA' ELSE 'A' END FROM NNM1

    Regards,

    Eric

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.