November 13, 2007 at 2:49 pm
CREATE PROC xxxRepVerJoel
@Table varchar(255)
AS
DECLARE @Tablename as varchar(255)
SET @Tablename = @Table
SELECT COUNT(*) FROM @Tablename
GO
--It gives me an error "Must Declare the Varible '@Tablename'
November 13, 2007 at 2:58 pm
A table named cannot be named dynamically via variable unless you use exec or sql_execute
November 13, 2007 at 3:05 pm
the other method is actually sp_executesql, which is better because it lets you reuse execution plans and has better parameter capabilities.
more info here:
November 13, 2007 at 3:50 pm
Thanks for you help. That did it.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply