-1

I am writing a query to get the specific value based on the CASE Statement. I am checking with two conditions. One for the value of the column name and other on the if another value exist in the other DE using CASE Statement.

Below is my code:

Select DISTINCT B.Pd, P.AB, P.GR,P.Pc,P.Ac, B.bt,
CASE
 When B.bt IN ('1a','1b') THEN 'YES'
 When B.bt IN ('20','30','40') AND B.Pd  IN (Select Pd from [Q4standard]) THEN 'YES'
 ELSE 'NO'
 END AS Migrated
FROM ProdData P 
INNER JOIN 
send_general B ON P.Ac = B.Ad
Where 
DATEDIFF(M, PP.Pc, GETDATE()) <= 12

Now, after running this query on query studio, I am getting an error

" Error saving the Query field.Incorrect syntax near '('. "

I am not sure how to solve this issue and how can I use those two conditions in one CASE Statement.

Please help me with this.

Thanks Adam

0

1 Answer 1

0

You could replace the sub-query in your case statement with a left join, assuming it's a 1:1 match:

Select
  B.Pd
, P.AB
, P.GR
, P.Pc
, P.Ac
, B.bt
, CASE
   When B.bt IN ('1a','1b') THEN 'YES'
   When B.bt IN ('20','30','40') AND q.pd is not null THEN 'YES'
   ELSE 'NO'
  END AS Migrated
FROM ProdData P 
INNER JOIN send_general B ON P.Ac = B.Ad
left join Q4standard as q on q.pd = b.pd
Where 
DATEDIFF(M, PP.Pc, GETDATE()) <= 12

Also Query Studio is not perfect and should not be considered the standard for what will (or will not) work in a Query Activity. QS introduces some weird things that are not real issues in normal, production queries.

1
  • Thanks @Adam, it worked fine. :)
    – Adam Coder
    Commented Nov 30, 2023 at 8:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .