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
精彩评论