1

I tried using this

select * into #tempdb  (
exec SSC.usp_abc_data '01/31/2017','L','G','1','17',Null)

It prompts out an error saying that

Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'exec'.
Msg 102, Level 15, State 1, Line 4
Kim
  • 771
  • 6
  • 23

1 Answers1

0

you can do it like so:

SELECT * INTO #TestTableT FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
'EXEC    [databasename].[schemaname].[sp name]')
-- Select Table
SELECT *
FROM #TestTableT;

so in your case it will be like:

SELECT * INTO  #tempdb FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
'EXEC    [databasename].SSC.usp_abc_data ''01/31/2017'',''L'',''G'',''1'',''17'',Null')
-- Select Table
SELECT *
FROM #tempdb;

Just remember to include the database name.

if you are getting error in this method enable ad hoc distributed queries by executing following query in SSMS you will need:

sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO

Answer referenced from here

Fuzzy
  • 3,810
  • 2
  • 15
  • 33