I am having an error I cannot see in the following dynamic SQL statement:
SET @sql_statement =
"INSERT INTO " +
@archive_db_name + ".dbo._TEST_TB_ACTIVE_ORDERS
SELECT " +
@reporting_db_name + ".dbo._TEST_TB_ACTIVE_ORDERS.*
FROM " +
@reporting_db_name + ".dbo._TEST_TB_ACTIVE_ORDERS
WHERE " +
@reporting_db_name + ".dbo._TEST_TB_ACTIVE_ORDERS.ORDER_ID
IN
(
select #tmp_table_order_ids.order_id
from #tmp_table_order_ids
)"
EXEC(@sql_statement)
The error is:
Msg 102, Level 15, State 1:
Server 'server_name', Line 5:
Incorrect syntax near 'IN'
But I cannot see any syntax errors at the location the error specifies. Could someone please kindly point out why I am getting this error?
Try changing the double quotes to single quotes