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)
 Dynamic ORDER BY

Author  Topic 

royv
Constraint Violating Yak Guru

455 Posts

Posted - 2001-11-21 : 12:36:45
I was reading the article on Dynamic Order By, but I cannot get it to work. I get a conversion error. Here is my code {NT4 SP6 SQL7-SP2):

create procedure spdynamicorderby @pintSortBy int=null

as

select account,accountnumber
from tblwhatever
where account='whatever'
order by case @pintSortBy when 1 then account when 2 then accountnumber else account end asc

When @pintSortBy=1, I get a 'Syntax error converting varchar value to int'. When @pintSortBy=2, it works fine. Any suggestions?

*************************
Just trying to get things done
   

- Advertisement -