开发者

Create variable name for table

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜