sql server - How can I parameterize the tablename in a CREATE TABLE expression? -


I was wondering if syntax have to have something like the following:

 < Code> announcement @MyTableNameVARCHAR (50) SET @ MyTableName = 'AccountSummary' Create table dbo @ MyTableName (id int NOT NULL identified (1,1), ACCOUNTID zero-sum actual int)   

Of course, not working above. I've worked with my scripts with EXEC , but it seems that it's complicated. I create a table with a parameter for tablename ?

  DECLARE @MyTableName NVARCHAR (50); SET @MyTableName = 'Account Beautiful'; DECLARE @Sql NVARCHAR (max); Set @Sql = N'CREATE table '+ QUOTENAME (@MyTableName) + N (Id int NULL identified (1,1), ACCOUNTID, not int amount minus execute real)' sp_executesql @Sql   

OR DECLARE @MyTableName NVARCHAR (50); SET @MyTableName = 'Account Beautiful'; DECLARE @Sql NVARCHAR (max); Set @Sql = N'CREATE table [@MyTableName] (id int NULL identified (1,1), ACCOUNTID not int, amount minus actual) execute sp_executesql @Sql, N '@ MyTableName NVARCHAR (50)', @ MyTableName < / Code>

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -