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 2000 Forums
 SQL Server Development (2000)
 Trouble with DESC

Author  Topic 

kgruber
Starting Member

6 Posts

Posted - 2001-06-29 : 15:06:02
I'm using ASP to write a stored procedure because at the moment I don't have access to the database any other way. I have an ORDER BY CASE clause that works fine until I specify DESC. Then I get a syntax error. Here's the sp:

sql = "CREATE proc search " _
& "@field1 bit, " _
& "@field2 bit, " _
& "@sort char(1)," _
& "AS SELECT * FROM project WHERE " _
& "((@field1=1 AND field1=1) OR " _
& "(@field2=1 AND field2=1) " _
& "ORDER BY CASE WHEN @sort='1' THEN CONVERT(char(30),date_posted,121) desc WHEN @sort='2' THEN CONVERT(char(30),date_updated,121) desc WHEN @sort='3' THEN project_name WHEN @sort='4' THEN region END"
conn.execute(sql)

This generates the error message:
Incorrect syntax near the keyword 'desc'.

If i take it out, everything is fine.


   

- Advertisement -