| Author |
Topic |
|
themoney32
Starting Member
20 Posts |
Posted - 2009-10-16 : 23:40:36
|
| I am a student and I am having a syntax error with the following query, can anyone help?WHEN "Meat/Poultry" THEN 'P'WHEN "Seafood" THEN 'P'WHEN "Produce" THEN 'V'WHEN "Vegetables" THEN 'V'WHEN "Grains/Cereal" THEN 'S'WHEN "Beverages" THEN 'O'WHEN "Condiments" THEN 'O'WHEN "Confections" THEN 'O' END; |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-16 : 23:42:01
|
[code]CASEWHEN "Meat/Poultry" THEN 'P'. . .END[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
themoney32
Starting Member
20 Posts |
Posted - 2009-10-16 : 23:43:44
|
| I put the CASE on top and still stuck with a syntax error |
 |
|
|
themoney32
Starting Member
20 Posts |
Posted - 2009-10-16 : 23:56:41
|
| Anyone seem to know what the problem may be? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-17 : 00:01:00
|
can you show us your complete query and also the exact error message ? Just "syntax error" is not very useful KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
themoney32
Starting Member
20 Posts |
Posted - 2009-10-17 : 00:02:55
|
| CASE CategoryNameWHEN "Dairy Products" THEN 'P'WHEN "Meat/Poultry" THEN 'P'WHEN "Seafood" THEN 'P'WHEN "Produce" THEN 'V'WHEN "Vegetables" THEN 'V'WHEN "Grains/Cereal" THEN 'S'WHEN "Beverages" THEN 'O'WHEN "Condiments" THEN 'O'WHEN "Confections" THEN 'O' END;SELECT * FROM productsonorder;And the message I get is this...You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE CategoryNameWHEN "Dairy Products" THEN 'P'WHEN "Meat/Poultry" THEN 'P'' at line 1 |
 |
|
|
themoney32
Starting Member
20 Posts |
Posted - 2009-10-17 : 00:05:20
|
| Also when I have this as my query I get results but the category that I am trying to put all the information to shows all of them as the default, the column name that represents P, V, S, and O, is called catcodeCASEWHEN "Dairy Products" THEN 'P'WHEN "Meat/Poultry" THEN 'P'WHEN "Seafood" THEN 'P'WHEN "Produce" THEN 'V'WHEN "Vegetables" THEN 'V'WHEN "Grains/Cereal" THEN 'S'WHEN "Beverages" THEN 'O'WHEN "Condiments" THEN 'O'WHEN "Confections" THEN 'O' END;SELECT * FROM productsonorder; |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-17 : 00:44:55
|
you cannot use CASE by itself. You need to use CASE in a select statement.example :select case when . . then . . . else . . . endfrom atable KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-17 : 00:46:38
|
Also you should post your question in a MySQL forum like dbforums.com or mysql.com. SQLTeam is a Microsoft SQL Server forum and you are posting in SQL Server 2008 forum. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|