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 2005 Forums
 Transact-SQL (2005)
 SQL Query Error (ORDER BY CASE...)

Author  Topic 

sth_Weird
Starting Member

38 Posts

Posted - 2012-03-29 : 03:02:17
hi,
I am using this sql query in sqlserver 2005, but it doesn't work for me :/


SELECT tErrorCodeReactions.*, tErrorCodeReaction2Device.ReactionPriority
FROM tErrorCodeReactions INNER JOIN tErrorCodeReaction2Device ON (tErrorCodeReactions.ReactionID = tErrorCodeReaction2Device.ReactionID) AND (tErrorCodeReaction2Device.DeviceID = 149)
ORDER BY CASE WHEN tErrorCodeReaction2Device.ReactionPriority >= 0 THEN tErrorCodeReaction2Device.ReactionPriority WHEN tErrorCodeReaction2Device.ReactionPriority < 0 THEN tErrorCodeReactions.ReactionValue


the error that is shown is: "Incorrect syntax near the 'SET' keyword". but there is no set keyword in the query? What's wrong with the query?

thx
sth_Weird

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-29 : 03:30:09
try highlighting only this query and execute it in the Query Window


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

Go to Top of Page

sth_Weird
Starting Member

38 Posts

Posted - 2012-03-29 : 05:51:02
I'm already using the query view to test it.
But I found out now that I simply forgot the 'END' keyword.
This is the first time I'm using the 'CASE' function and when I googled for examples those that I found were usually stored procedures and I thought the END keyword belonged to the the stored procedure declaration.
Anyway thank you for you answer!

sth_Weird
Go to Top of Page
   

- Advertisement -