Create SQL 2008 R2 Table using a passed table name parameter
Is it possible to pass a table name parameter to a stored procedure which in turn creates a table that has the name passed by the parameter.
I have tried a number of things - see code attached - but I can't seem to get the stored procedure to substitute the passed parameter table name in the Create command.
The sp actually creates a table but creates it with the name - ' + tablename + ' -
It was suggested in various internet articles that the @Tablename nvarchar(50) line of code should be defined as @Tablename sysname (instead of the nvarchar(50) - which I tried but it still created the table with the ' + @Tablename + ' name.
Other articles suggested that this could be achieved by using dynamic SQL but I can't see why my SP can't substitute the name passed by the parameter.
If anyone can shed so light on this or can point out what I'm doing wrong I'd be most grateful as I spent hours on this but getting nowhere fast.