Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fieldname as parameter..? 1

Status
Not open for further replies.

kenjoswe

Technical User
Sep 19, 2000
327
SE
Hi all,

Is it possible to substitute a fieldname in a stored procedure with a parameter something like:

@Field varchar(50)
select * from Table1
where @Field= 'criteria'

/Kent J.
 
Yes,
But you will have to exec the statement:

DECLARE @Field varchar(50)
DECLARE @Str VARCHAR(255)
SELECT @Field = 'MyField'

SELECT @Str = "SELECT * FROM Table WHERE ' + @Field + ' =
'''criteria'''
EXEC (@str)

I think this is what you mean,

Chris Dukes



 
Thanks! That really helped me!

/Kent J.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top