need help
-
hello i wanted to make a single stored procedure which takes as parameter the table name from which all the rows should be selected ... in query analyzer i tried declare @var varchar(30); set @var='tableName'; select * from @var; but it won't work... the variable declaration and assignment works fine, but the select statement doesnt work... Please help in this regard... i also tried making declare @col_name varchar(30); set @col_name='studentName'; select @col_name from studentTable; it works but the rows returned have col_name as it's value and the original value doesn't appear Plz help
haseeb
-
hello i wanted to make a single stored procedure which takes as parameter the table name from which all the rows should be selected ... in query analyzer i tried declare @var varchar(30); set @var='tableName'; select * from @var; but it won't work... the variable declaration and assignment works fine, but the select statement doesnt work... Please help in this regard... i also tried making declare @col_name varchar(30); set @col_name='studentName'; select @col_name from studentTable; it works but the rows returned have col_name as it's value and the original value doesn't appear Plz help
haseeb
You have to use Dynamic EXECUTE or sp_executesql (recommended). Check Books Online sp_executesql topic. It has a good example.