Insert results of a stored procedure into a temporary table

T.Zacks 3,996 Reputation points
2021-02-19T19:31:41.297+00:00

I tried this code but got error
https://stackoverflow.com/a/29040625/9359783

SELECT * 
INTO #temp
FROM OPENROWSET('SQLNCLI', 
                'Server=192.17.11.18;Trusted_Connection=yes;', 
                'EXEC [USP_Delta_Test]  ADS,ADS')

select * from #temp
drop table #temp

Normally when executing SP like this way then getting data EXEC [USP_Delta_Test] 'ADS','ADS'
this is my server IP 192.17.11.18

please tell me what i need to change in my above code ?

Developer technologies | Transact-SQL
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-02-19T20:10:37.39+00:00

    Maybe you should change this line, inserting apostrophes:

    'EXEC [USP_Delta_Test] ''ADS'', ''ADS'''
    

  2. MelissaMa-MSFT 24,221 Reputation points
    2021-02-22T02:37:05.337+00:00

    Hi @T.Zacks ,

    Please refer a thorough list of troubleshooting methods that can be used to connect to the SQL server from below:

    1. Make sure SQL Server Service is running( run services.msc).
    2. If a named instance, make sure SQL Server browser service is running.
    3. Make sure SQL Server is configured to allow remote connections.
    4. Check the SQL Server error log and confirm SQL is listening on the expected network interfaces and ports.
    5. Test server connectivity with PING from the client machine.
    6. Test port connectivity using TELNET(TELNET <server-name> 1433).
    7. Check firewall settings or reate a Firewall exception.
    8. Check Local connection.

    You could also refer more detailed steps in this article.

    Best regards
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.