Tuesday, March 27, 2012

Create Table Question T-Sql

Why can't I do this :

declare @.strUserName varchar (255)
declare @.strTableName varchar (255)

set @.strUserName = 'alan'
set @.strTableName = 'Table' + @.strUsername

CREATE TABLE @.strTableName(
[DistinctLifeID] [int] NULL,
) ON [PRIMARY]

Is there a way to pass a variable Name into a create statement for a table in T-SQL

Cheers :rolleyes:Try it with the EXECUTE statement:

DECLARE @.tablename varchar(255)
EXEC ('CREATE TABLE ' + @.tablename + '...')

peter|||Thanks Peter

You are indded the man

:cool:

No comments:

Post a Comment