开发者

Create variable name for table

开发者 https://www.devze.com 2023-02-01 07:46 出处:网络
I\'m wondering if it is possible to create a variable name when copying a table to another. Here\'s my sort-of algorithm/code

I'm wondering if it is possible to create a variable name when copying a table to another.

Here's my sort-of algorithm/code

DECLARE @NewTableName VARCHAR(50)
SET @NewTableName = 'MyTable_'+GETDATE() --MyTable_12282010 (for example)

SELECT *
IN开发者_如何学编程TO @NewTableName
FROM MyTable

I'm wondering if this is possible. I tried it before, but it failed. Any suggestions guys?


It is possible, but only using dynamic TSQL.

See sp_executesql (or the 2000 version sp_executesql)

Be aware of The Curse and Blessings of Dynamic SQL

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号