Skip to Content

Problem with Case when null

Hi Experts,

My requirement is as below this condition I am using in derived table but not able to parse because of some times it is showing

<<< Encountered "IS" at line 8, column 39.

Was expecting one of:

"then" ...

"and" ...

"or" ...

>>>

If I Use "IF NULL" in same code instead of "IS NULL" Then getting below error

<<<<<<<Encountered "IN" at line 9, column 54.

Was expecting one of:

"when" ...

"else" ...

"end" ...

"+" ...

"-" ...

"*" ...

"/" ...

"**" ...

"//" ...

"%" ...

"." ...

>>>>>

This below mentioned euwry i am using

Select

Max(Table__1."0PSTNG_DATE") As Date

From @catalog('NM1')."PUBLIC"."IZDSO_DMR" Table__1

Where

CASE When

Table__1."0MOVETYPE" IN (601,602) IS NULL

THEN

Table__1."0MOVETYPE" IN (201,202,261,262)

When

Table__1."0MOVETYPE" IN (201,202,261,262) IS NULL

THEN

Table__1."0MOVETYPE" IN (101,102,131, 132 )

When

Table__1."0MOVETYPE" IN (101,102,131,132 ) IS NULL

THEN

Table__1."0MOVETYPE" IN (501,502 )

ELSE

Table__1."0MOVETYPE" IN (601,602)

END .

Please correct the query,

Thanks,

G Sampath Kumar

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Jan 21, 2014 at 05:04 AM

    Hi Please find the logic below:

    SELECT "0PLANT", "0MATERIAL",
    (case when sum(case when "0MOVETYPE" = 602 then 1 else 0 end) > 0
    then max(case when "0MOVETYPE" = 602 then "0PSTNG_DATE" end)
    when sum(case when "0MOVETYPE" = 601 then 1 else 0 end) > 0
    then max(case when "0MOVETYPE" = 601 then "0PSTNG_DATE" end)
    when sum(case when "0MOVETYPE" = 102 then 1 else 0 end) > 0
    then max(case when "0MOVETYPE" = 102 then "0PSTNG_DATE" end)
    when sum(case when "0MOVETYPE" = 101 then 1 else 0 end) > 0
    then max(case when "0MOVETYPE" = 101 then "0PSTNG_DATE" end)
    end) as Last_Sales_Date
    \FROM "NM1"."PUBLIC"."IZDSO_DMR" Table__1
    Group By "0MATERIAL", "0PLANT"

    Thanks,

    G Sampath Kumar

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 26, 2013 at 02:26 PM

    What database (Oracle, SQL Server, etc.) is this based upon?

    Noel

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member sampath guntha

      Looks like you are having 2 condition in the same when without using and and or... Also if your field is having data type as char only then you can compare it with null.. Looks like in your condition you have both data type as number and char which should not be the case..

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.