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 |
|
Swigbert
Starting Member
1 Post |
Posted - 2002-04-23 : 17:14:04
|
| I'm trying to pass a tablename to a sp and have the sp populatethe table. Error msg is needing to declare the variable I've assignedthe tablename to.create procedure PopGolf @dbGreat varchar(30), @lineno intasdeclare @tablename varchar(128)declare @stopval intdeclare @recordname varchar(30)declare @count intset @stopval = @linenoset @tablename = (select name from sysobjects where name = @dbGreat)set @count = (select count(*) from MastersGolf)set @count = @count + 1set @count = 1while (@count < @stopval)beginset @recordname = 'GolfGreat'+cast(@count as varchar)insert @tablename values (@count, @recordname, GETDATE())set @count = @count + 1endgo |
|
|
royv
Constraint Violating Yak Guru
455 Posts |
Posted - 2002-04-23 : 17:53:37
|
| Here is how I would do it:create procedure PopGolf @dbGreat varchar(30), @lineno int as declare @tablename varchar(128) declare @stopval int declare @recordname varchar(30) declare @count int set @stopval = @lineno select @tablename=name from sysobjects where name = @dbGreatselect @count=count(*) from MastersGolfset @count = @count + 1 set @count = 1 while (@count < @stopval) begin set @recordname = 'GolfGreat'+cast(@count as varchar) EXEC('insert ' + @tablename + 'values (@count, @recordname, GETDATE())')set @count = @count + 1 end go*************************Just trying to get things done |
 |
|
|
|
|
|