Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a loopback linked server to the local instance, making sure that data access is enabled. Let's say you have a local named instance called <code>YourServer\SQL2008</code>:</p> <pre><code>USE [master]; GO EXEC sp_addlinkedserver @server = N'LoopbackLocal', @srvproduct = N'', @provider = N'SQLNCLI', @datasrc = N'.\SQL2008', @catalog = N'tempdb'; GO EXEC sp_serveroption @server = N'LoopbackLocal', @optname = N'collation compatible', @optvalue = N'true'; GO EXEC sp_serveroption @server = N'LoopbackLocal', @optname = N'data access', @optvalue = N'true'; GO EXEC sp_addlinkedsrvlogin @rmtsrvname = N'LoopbackLocal', @locallogin = NULL , @useself = N'True'; GO -- you may need to configure other security here </code></pre> <p>Then you can use <code>OPENQUERY</code> to run a stored procedure as if it were an ad hoc query.</p> <pre><code>SELECT COUNT(*) FROM OPENQUERY ( LoopbackLocal, 'EXEC dbo.my_sp' ) AS y; </code></pre> <p>Now, if <code>dbo.my_sp</code> dumps information into a #temp table first, you're going to have issues, since it is no longer a block of code that <code>OPENQUERY</code> can process. For example, if you try to execute <code>sp_who2</code> this way, at least in SQL Server 2012, you will get an error from <code>sp_describe_first_result_set</code> which <code>OPENQUERY</code> has been altered to use (so maybe this works for you now, I don't have 2008 to test, but it will be an issue someday):</p> <blockquote> <p>Msg 11526, Level 16, State 1, Procedure sp_describe_first_result_set, Line 1 <br>The metadata could not be determined because ... uses a temp table.</p> </blockquote> <p>If you're going to be doing this a lot, however, why not make specialized stored procedures (or add options to these ones) such that only a count is returned?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload