-
Passing Fields as Parameter of Stored Procedure
Does anyone know how to pass a list of fields into a stored procedure and then use those fields in a select statement. Here's what I'm trying to do.
I have a front end application that allows the user to pick the fields they want return as a record set. Currently, all this is being done in the application. But, I'd like SQL to do it, if it's possible.
I'd pass the following into a stored procedure.
Set @Fields = "First, Last, ID" -- This is done in the application
Exec usp_return @Fields
Obviously, the following fails stored procedure doesn't work ...
CREATE PROCEDURE @FIELDS varchar(255) AS
SELECT @FIELDS FROM MY_TABLE
~~~~~~~~~~~~~~~
Any ideas?
MAPMAN
-
Passing Fields as Parameter of Stored Procedure (reply)
Here's the answer. For those who are interested.
The stored procedure should read:
CREATE PROCEDURE usp_Return @Fields as varchar(255)
AS
Execute ('Select ' + @Fields + ' from My_Table'
So, if I set a variable to:
@Fields_I_Want = 'First, Last, ID'
and do the following
Exec usp_Return @Fields_I_Want
It will works.
Mapman
------------
MAPMAN at 7/6/00 1:22:51 PM
Does anyone know how to pass a list of fields into a stored procedure and then use those fields in a select statement. Here's what I'm trying to do.
I have a front end application that allows the user to pick the fields they want return as a record set. Currently, all this is being done in the application. But, I'd like SQL to do it, if it's possible.
I'd pass the following into a stored procedure.
Set @Fields = "First, Last, ID" -- This is done in the application
Exec usp_return @Fields
Obviously, the following fails stored procedure doesn't work ...
CREATE PROCEDURE usp_Return @FIELDS varchar(255) AS
SELECT @FIELDS FROM MY_TABLE
~~~~~~~~~~~~~~~
Any ideas?
MAPMAN
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|