Creating SQL table using dynamic variable name

前端 未结 5 941
滥情空心
滥情空心 2021-02-05 17:23

I want to create backup SQL tables using variable names.

something along the lines of

DECLARE @SQLTable Varchar(20) 
SET @SQLTable = \'SomeTableName\' +         


        
5条回答
  •  独厮守ぢ
    2021-02-05 18:03

    DECLARE @Script NVARCHAR(MAX);
    SET @Script = N'SELECT * INTO SomeTableName_' + N'20100526' + N' FROM SomeTableName';
    EXEC sp_executesql @Script
    

    I've left the date separate as I assume you want to calculate it for every run.

提交回复
热议问题