I am fairly new to SQL and need a bit of help. I don't know if this is possible but I'd like to be able to use a variable in a table name when creating a new table. I've tried the code below but I only get a table named '@tablename' (my variable name). I'm trying to assign a month + year to a new table name creating a list of monthly snapshots of a particular table.
DECLARE @tablename VARCHAR(30)
SET @tablename = 'patsnapshot' + str(datepart(month, CURRENT_TIMESTAMP) - 1)+ str(datepart(year, CURRENT_TIMESTAMP) - 1)
I you could let me know if/how this can be done it would be much appreciated. Thanks.