Tuesday, March 27, 2012

create a table naming it from a variable

How can I leave the table name in a create statement as a variable?
DECLARE @.tname varchar(32)
SET @.tname = 'ralph'
CREATE TABLE @.tname...
I need to create tables/temp tables for multiple ado.net users and I
hope to gain some performance improvements over dynamic sql.
thx
md
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!You do this via dynamic SQL, like so:
DECLARE @.tname varchar(32)
SET @.tname = 'ralph'
DECLARE @.CMD varchar(1000)
set @.CMD = 'CREATE TABLE ' + rtrim(@.tname) + ' (Id int, code int)'
exec (@.cmd)
insert into ralph values (1, 1)
select * from ralph
drop table ralph
--
----
----
-
Need SQL Server Examples check out my website
http://www.geocities.com/sqlserverexamples
"M D" <mardukes@.aol.com> wrote in message
news:ery$E95DFHA.3536@.TK2MSFTNGP15.phx.gbl...
> How can I leave the table name in a create statement as a variable?
> DECLARE @.tname varchar(32)
> SET @.tname = 'ralph'
> CREATE TABLE @.tname...
> I need to create tables/temp tables for multiple ado.net users and I
> hope to gain some performance improvements over dynamic sql.
> thx
> md
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!

No comments:

Post a Comment