Take dynamic sql result with variable and place into a table on sql server
Take dynamic sql result and place into a table on sql server
I have this Dynamic sql query working fine.DECLARE @StartDate AS VARCHAR(10), @SQL NVARCHAR(MAX);SET @StartDate = '01-JAN-19';SET @SQL = 'SELECT * FROM OPENQUERY(XREF_PROD, ''SELECT leavetype, leavereason FROM XREF.XREF_CALENDER WHERE createdon >= ''''' + @StartDate + ''''''')'; EXEC sp_executesql @SQL;
I need to take this result now and INSERT it into table on sql server.
Database name = Work_Flow
Table Name= Customer_Calendar
Fields = leavetype, leavereason
I have looked at kinds of examples on the internet..but gets confusing because most of the examples use a temp table.
I will be asking another question based on this one in regards to having 2 parameters..
@Startdate @ Enddate
fordraiders
Andrei Fomitchev
DECLARE @StartDate AS VARCHAR(10),
@SQL NVARCHAR(MAX);
SET @StartDate = '01-JAN-19';
SET @SQL = ' INSERT INTO Work_Flow.dbo.Customer_Calendar
SELECT * FROM OPENQUERY(XREF_PROD, ''SELECT leavetype, leavereason FROM XREF.XREF_CALENDER WHERE createdon >= ''''' + @StartDate + ''''''')';
Open in new window
Use unambiguous date literals if possible.