Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Passing a column name to a sproc


Message #1 by Amir Meskovic <meskovic@e...> on Thu, 31 May 2001 16:36:47 +0400
Try this:

CREATE SPROC dbo.GetAll 
		@SortBy varchar(100)
	AS
		EXEC( 'SELECT * FROM USERS ORDER BY ' +@SortBy)
Lefteris

-----Original Message-----
From: Amir Meskovic [mailto:meskovic@e...]
Sent: Thursday, May 31, 2001 3:37 PM
To: sql language
Subject: [sql_language] Passing a column name to a sproc


Hi All,

I have a stored procedure which I call with a com object.
I would like to pass a parameter to the stored procedure
as a colum name. For example 
	
	CREATE SPROC dbo.GetAll 
		@SortBy varchar(100)
	AS
		SELECT * FROM USERS ORDER BY @SortBy
	GO

When I try to do this I get an error message that I can not
use varchar to reference a column name.

Can anyone help ?

Amir Meskovic

		



  Return to Index