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: Of course, not working above. I've worked with my scripts with OR < Code> announcement @MyTableNameVARCHAR (50) SET @ MyTableName = 'AccountSummary' Create table dbo @ MyTableName (id int NOT NULL identified (1,1), ACCOUNTID zero-sum actual int)
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
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
Post a Comment