0

My SQL query looks something like this and am executing it in SQLCMD mode in SSMS:

DECLARE @tempTable TABLE(acct nvarchar(50))

INSERT INTO @tempTable (Acct) 
   (select acct from tUsers)

:CONNECT otherserver

USE XXXDb

Select * 
from tUserInfo 
inner join @tempTable on tUserInfo.Acct = @tempTable.Acct

GO

The problem is :

Before inserting all the records into @tempTable, the :CONNECT gets executed. Hence the query fails :( :( :(

Please help me out :(

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

If you are trying to get data form Other server then you can do this;

DECLARE @tempTable TABLE(
    acct nvarchar(50)
)

INSERT INTO @tempTable (Acct) (select acct from tUsers)

Select * from 
[otherserver].[XXXDb].[dbo].[tUserInfo] as ui 
inner join @tempTable on ui.Acct = @tempTable.Acct
GO

Please refer this answer for how one can query on a DB on other server.

Community
  • 1
  • 1
Praveen
  • 8,945
  • 4
  • 31
  • 49