I am using the OPENROWSET
command to execute the query.
I want the result value must be inserted into the temp table like
SELECT * INTO #TempTable EXEC @query
but it shows an error of
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
Can anyone tell me how can I execute the query and insert into temp table?
The sample code is
declare @Query nvarchar(max)
SET @Query ='SELECT
*
FROM
OPENROWSET
(
''SQLNCLI'',
''servername'';
''db'';
''pwd'',
''set nocount on;
set fmtonly off;
exec databaseName.dbo.spname ''''param1 '''',''''param2'''',''''param3'''',''''param3'''' ''
)
'
select * into #temp exec sp_executesql @Query