I am getting the following error though I have given the with result sets the dynamic SQL. Yet it asks for the same.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "The metadata could not be determined because statement 'EXEC sp_executesql @ExecSQL' contains dynamic SQL. Consider using the WITH RESULT SETS clause to explicitly describe the result set.".
Error: 0xC0202080 at Ingest The CSV File - Flow, OLE DB Command 1 [281]: Unable to retrieve destination column descriptions from the parameters of the SQL command.
The below code works fine in MS SQL Management Studio Query. But it gives error in SSIS
DECLARE @tablename nvarchar(200), @tablevalue nvarchar(1)
SELECT @tablename =CAST(FLOOR(RAND()*(100000-5+1)+5) as nvarchar)
Select @tablevalue='0'
DECLARE @ExecSQL NVARCHAR(max)
SET @ExecSQL = 'SELECT d.tablename, d.tablevalue INTO mws_ssis_cust_senti_integration'+ @tablename+
+ ' from ( select ''' + 'mws_ssis_cust_senti_integration' + @tablename + ''' as tablename, ''' + @tablevalue + ''' as tablevalue ) as d '
EXEC sp_executesql @ExecSQL
Set @tablename = N'mws_ssis_cust_senti_integration'+ cast(@tablename as nvarchar)
Set @ExecSQL = 'select * from ' + @tablename
EXEC sp_executesql @ExecSQL
WITH RESULT SETS
(
(
tablename varchar(max), tablevalue varchar(1)
)
)