0

I have a table containing these values:

object particular ----------------------- AD hammer AD stone PD nail PR rocket OBR trophy 

by using a CASE statement how can I select both AD and PD ? Here's what I did:

object = CASE WHEN 'PD' OR 'AD' THEN 'PD' AND 'AD' ELSE 'OBR' END 

I know this is wrong, could someone point me in the right direction?

6
  • 6
    What do you want to do exactly? Commented May 15, 2016 at 11:35
  • 1
    Don't you just want to SELECT object, particular from <tablename> where object = 'AD' OR object = 'PD'? Commented May 15, 2016 at 11:36
  • i just want to know how can i do it using the case statement when the parameter = true then it will display both values from like AD and PD :) Commented May 15, 2016 at 11:43
  • 1
    So if we understood correctly, you just want to select the rows from the table where object is AD or PD. Correct? Commented May 15, 2016 at 11:55
  • yups..i want to display both data from AD and PD..by using case statement :) Commented May 15, 2016 at 12:08

3 Answers 3

2

Why can't you just use an OR condition in your select?

SELECT object FROM table_name WHERE object = 'AD' OR object = 'PD' 
Sign up to request clarification or add additional context in comments.

Comments

1

Is this what you are looking for :

SELECT CASE WHEN object = 'AD' or object = 'PD' THEN ... ELSE ... END AS <newColumnName> FROM <table> 

2 Comments

after the THEN keyword..i put 'PD' and 'AD'..and it gives me error..is that even possible ? :)
@yoyieyoyie - you need to put the entire implementation into the question for us to look into it
0

object = CASE WHEN 'PD' OR 'AD' THEN 'PD' AND 'AD' ELSE 'OBR' END

CORRECT SYNTAX: CASE WHEN <condition> THEN <value1> ELSE <value2> END 

You have an incorrect syntax in the higlighted part

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.