Fordraiders
asked on
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 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.
Thanks
fordraiders
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.
Thanks
fordraiders
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to both answers..
I will be asking another question based on this one in regards to having 2 parameters..
@Startdate @ Enddate
fordraiders
I will be asking another question based on this one in regards to having 2 parameters..
@Startdate @ Enddate
fordraiders
DECLARE @StartDate AS VARCHAR(10),
@SQL NVARCHAR(MAX);
SET @StartDate = '01-JAN-19';
SET @SQL = ' INSERT INTO Work_Flow.dbo.Customer_Cal endar
SELECT * FROM OPENQUERY(XREF_PROD, ''SELECT leavetype, leavereason FROM XREF.XREF_CALENDER WHERE createdon >= ''''' + @StartDate + ''''''')';
EXEC sp_executesql @SQL;
@SQL NVARCHAR(MAX);
SET @StartDate = '01-JAN-19';
SET @SQL = ' INSERT INTO Work_Flow.dbo.Customer_Cal
SELECT * FROM OPENQUERY(XREF_PROD, ''SELECT leavetype, leavereason FROM XREF.XREF_CALENDER WHERE createdon >= ''''' + @StartDate + ''''''')';
EXEC sp_executesql @SQL;
INSERT INTO Work_Flow.dbo.Customer_Cal endar (leavetype, leavereason) ...
Open in new window
Use unambiguous date literals if possible.