-1

SQL query:

"SELECT Store_Name, CASE Store_Name WHEN 'abc','xyz' THEN Sales * 2  ELSE Sales END FROM Store_Information";

Are two values in "WHEN" clause allowed like in above query - WHEN 'abc','xyz' THEN Sales * 2?

EDIT: I don't need to run this query. I need to parse this query. I am getting this from Tableau.

I want to know is this Query syntactically correct?

Dev
  • 13,492
  • 19
  • 81
  • 174
  • 1
    Which RDBMS is this for? Please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s Dec 30 '15 at 11:17
  • 1
    Possible duplicate of [SELECT using 'CASE' in SQL](http://stackoverflow.com/questions/21313025/select-using-case-in-sql) – Mohith Kumar Dec 30 '15 at 11:21
  • Running the query would have given you the answer much faster than the time it took to ask the question. But I'll answer your question anyway. It's not syntactically valid. – Dan Bracuk Dec 30 '15 at 12:08
  • The simple answer is, "no". – Dan Bracuk Dec 30 '15 at 12:22
  • @DanBracuk Thanks for replying.Tableau is internally sending this type of query to my driver. SQL Parser is not able to understand it. I did not find much on google. So, I asked here – Dev Dec 30 '15 at 12:32

1 Answers1

2

You have two options.

1) Simple case expression

CASE Store_Name
   WHEN 'abc' THEN Sales * 2
   WHEN 'xyz' THEN Sales * 2
   ELSE Sales
END

2) Searched case expression. I think it would be better choice for your task

CASE WHEN Store_Name IN('abc', 'xyz')
     THEN Sales * 2
     ELSE Sales
END
fabulaspb
  • 1,238
  • 8
  • 9
  • I am not asking an alternate way to achieve this. Just want to know is this syntactically correct? – Dev Dec 30 '15 at 12:15
  • @Tom Tableau is internally sending this type of query to my driver. SQL Parser is not able to understand it. I did not find much on google. So, I asked here. – Dev Dec 30 '15 at 12:30