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 |
|
shammad
Starting Member
3 Posts |
Posted - 2011-04-20 : 09:38:20
|
| Hi,is there a way to use dynamic columns name in a Stored Procedure, I mean some thing like :ALTER PROCEDURE [SearchApplication] @Name nvarchar(50), @Prop nvarchar(50)ASBEGIN SELECT * FROM Application as app WHERE @Prop Like '%'+@Name+'%'ENDwhere @Prop will change depends on the parameter.please advice,Thanks in advance |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-04-20 : 09:45:14
|
| ALTER PROCEDURE [SearchApplication]@Name nvarchar(50),@Prop nvarchar(50)ASBEGINdeclare @sql varchar(1000)select @sql = 'SELECT * FROM Application as app WHERE [' + @Prop + '] Like ''%'+@Name+'%'''exec (@sql)ENDsee http://www.nigelrivett.net/SQLTsql/TableNameAsVariable.html==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
shammad
Starting Member
3 Posts |
Posted - 2011-04-20 : 09:54:48
|
| Great, it is working thank you :) |
 |
|
|
|
|
|