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 |
|
Mazdak
Yak Posting Veteran
63 Posts |
Posted - 2003-02-06 : 08:07:41
|
| I want to write a store procedure that SELECT from a table.I want to pass the name of table to store procedure as an argument.I write this code:CREATE PROCEDURE sp_Vote_GetVoteArray@Table nvarchar(50),@ID int ASSELECT col1 FROM @Table WHERE id=@IDBut it gives me error that @Table variable must declare! |
|
|
simondeutsch
Aged Yak Warrior
547 Posts |
Posted - 2003-02-06 : 10:28:07
|
| Seems like you are using SQL 2000, which supports table variables, but it doesn't look like that's what you want here. If you are trying to have a dynamic Select over any table, you need to use dynamic sql and change your query to look like this:EXEC('SELECT Col1 FROM ' + @Table + ' WHERE ID = ' + @ID)or put your select string into a string variable like this:Declare @strSelect varchar(250)set @StrSelect = 'SELECT Col1 FROM' + @Table + ' WHERE ID = ' + @IDEXEC @strSelectSarah Berger MCSD |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|