Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Syntax Error

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]
CASE
WHEN "Meat/Poultry" THEN 'P'
. . .
END
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

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
Go to Top of Page

themoney32
Starting Member

20 Posts

Posted - 2009-10-16 : 23:56:41
Anyone seem to know what the problem may be?
Go to Top of Page

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]

Go to Top of Page

themoney32
Starting Member

20 Posts

Posted - 2009-10-17 : 00:02:55
CASE CategoryName
WHEN "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 CategoryName
WHEN "Dairy Products" THEN 'P'
WHEN "Meat/Poultry" THEN 'P'
' at line 1
Go to Top of Page

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 catcode

CASE
WHEN "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;
Go to Top of Page

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 . . . end
from atable



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

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]

Go to Top of Page
   

- Advertisement -