Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Apprentice
Starting Member
3 Posts |
Posted - 2005-01-24 : 04:34:30
|
| Is this possible? I would like to pass a column_name into a stored procedure. im using sql server 2000i tried this code but it didn't workcreate procedure test @field varchar(30),@query varchar(30)OUTPUT AS select * from table where @field=@queryRETURN 0execute test 'fieldname', 'string' |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2005-01-24 : 04:38:15
|
| you need to use dynamic sql ...something like create procedure test @field varchar(30),@query varchar(30)AS begindeclare @SQL nvarchar(1000)set @sql ='select * from table where '+@field+'='+@querysp_executesql @sqlendHe is a fool for five minutes who asks , but who does not ask remains a fool for life!http://www.sqldude.4t.comhttp://www.sqljunkies.com/weblog/sqldude |
 |
|
|
Apprentice
Starting Member
3 Posts |
Posted - 2005-01-26 : 01:32:00
|
| Thank you very much for the tip. this is what i didcreate procedure sample @field nvarchar(10),@query nvarchar(10) asdeclare @sqlstatement nvarchar(4000)set_quoted_identifier offset @sqlstatement='select * from table where ' + @field +'= "' + @query + '"'exec sp_executesql @sqlreturn 0 |
 |
|
|
|
|
|