I want to insert into a table the following information:
Week NoTrans Spend
02.01.12-08.01.12 11 520
The script I have is:
DECLARE @Week VARCHAR(22)
DECLARE @Date1 DATETIME
DECLARE @Date2 DATETIME
DECLARE @Script VARCHAR(8000)
SET @date1 = '02 Jan 2012'
SET @date2 = '08 Jan 2012'
SET @Week = Convert(varchar(12), @date1, 104)+'-'+Convert(varchar(12), @date2, 104)
PRINT @Week
SET @Script = 'INSERT INTO table2 (WEEK, NoTrans, Spend)
SELECT '+ @WEEK +', Transactions, Spend
FROM table1 (NOLOCK)
EXEC @Script
The Week
column comes from @Week
not table1.
I'm getting the following error message:
Msg 203, Level 16, State 2, Line 20
The name 'INSERT INTO table2 (WEEK, Transactions, Spend) SELECT 02.01.2012-08.01.2012, Transactions, Spend FROM table1 (NOLOCK)' is not a valid identifier.
Thanks