Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Stroed Proc passing variable to order sql statement


Message #1 by stephen.trigg@p... on Mon, 18 Feb 2002 11:02:00
Thanks Siva,

That has worked great... I had a big query with lots of variables to 
create into a string which was fun but your solution worked fine.

Cheers,
Stephen

> 
> Hi
> You can try something like below. I tried and it works.
> 
> CREATE PROCEDURE proc_Test
>  @orderbyfield nvarchar(250) 
> AS
> 
> declare @sqlQuery nvarchar(250)
> set @sqlQuery = 'Select Field1,Field2 from SampleTable order by' +
> @orderbyfield + ' Asc '
> Exec(@sqlQuery)
> 
> 
> Let me know if it solved your problem.
> Siva.
>   

  Return to Index