Case Statement Error

  • I am getting the following error:

    Msg 156, Level 15, State 1, Line 9

    Incorrect syntax near the keyword 'CASE'.

    Here is my code...can anyone see what I don't seem to be seeing?

    select glbank.check_num

    , glbank.ref_num

    , glbank.check_amt

    , glbank.check_date

    , glbank.bank_code

    , vendor.vend_num

    , vendor.vend_remit

    , vendaddr.[name]

    CASE

    WHEN v.vend_remit IS NULL THEN Left(Upper(IsNull(va.name,'')),75)+Space(75-Len(Left(IsNull(va.name,''),75)))

    ELSE Left(Upper(IsNull(vr.name,'')),75)+Space(75-Len(Left(IsNull(vr.name,''),75)))

    END

    FROM aptrxp_all a

    join vendor v

    ON a.vend_num = v.vend_num

    join vendaddr va

    ON a.vend_num = va.vend_num and

    left outer join vendaddr vr

    ON v.vend_remit = vr.vend_num

    left outer JOIN glbank

    ON a.check_num=glbank.check_num

    WHERE glbank.check_amt = '4935.28'

  • looks like a missing comma before the CASE statement.

    I'd also recommend to add an alias to your CASE .. END. 😉



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Hi

    It should be like , or peranthss error.so use Edit++ then u will be findout the problem like where u miss the , or open and close

    Thank you very much

    Regards

    sank

  • LutzM (11/30/2010)


    looks like a missing comma before the CASE statement.

    I'd also recommend to add an alias to your CASE .. END. 😉

    apart from the above your code is also

    having written wrongley at

    ON a.vend_num = va.vend_num and

    left outer join vendaddr vr

    and after the on statement should be one more condition for the join, noty the other join it self(left outer join vendaddr vr)

  • sharath.chalamgari (11/30/2010)


    LutzM (11/30/2010)


    looks like a missing comma before the CASE statement.

    I'd also recommend to add an alias to your CASE .. END. 😉

    apart from the above your code is also

    having written wrongley at

    ON a.vend_num = va.vend_num and

    left outer join vendaddr vr

    and after the on statement should be one more condition for the join, noty the other join it self(left outer join vendaddr vr)

    Just eliminate the and at the end of that line and it should fix that problem.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Thanks LutzM...always comes down to a syntax error doesn't it, LOL. And to the other responses, yes I did catch the word "and" which was in there when I was trying something and just forgot to take it out.

    Once I added the comma it worked perfectly. Again, thanks for all the responses!

Viewing 6 posts - 1 through 5 (of 5 total)

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