1

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 *
INTO @NewTableName
FROM MyTable

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

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

is it applicable for sql server 2000?
@Musikero31: if this answer (or another) is helpful, please don't forget to mark it as 'Accepted'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.