I'm trying to store the result of a stored procedure in a temp table, therefore I have to call it using OPENROWSET however when executing the query
DECLARE @sql nvarchar(MAX)
DECLARE @callToProc nvarchar(255)
SET @callToProc = 'EXEC dbo.mySpName @param1=' + CAST ( 1 AS nvarchar(200) ) + ', @param2= ''Achat'' '
SET @sql = 'SELECT * INTO #mytempTab FROM OPENROWSET(''SQLNCLI'', ''Server=myserv;Trusted_Connection=yes;'', ' + @callToProc + ') AS myalias'
EXECUTE(@sql)
I get the following error :
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'EXEC'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.
But I really don't see what is wrong with my request
Thanks !