I want to pass a user value through a variable in the order by clause and also wanna pass value of ASC/DESC through variable from the web application. Please Help
Using Variables in Order By Clause
Collapse
X
-
The only way I know is to concatenate all necessary variables in SQL statement first and then execute it.
The problem is that variables have length limitations.
Example:
[PHP]Declare @OrderBY varchar(20),
@Order varchar(10), @SQL varchar(8000)
Set @OrderBY = 1
Set @Order = 'desc'
select @SQL = 'Select * from sysobjects Order by ' + @OrderBY + ' ' + @Order
execute(@SQL)[/PHP]
Comment