--Open
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
GO
declare @TUser table
(
[UserId] [int],
[UserName] [varchar](50),
[User_Password] [varchar](50),
[Firm] [varchar](50),
[Email] [varchar](50),
[LastLogin] [datetime],
[DefaultRole] [int]
)
insert @TUser
select * from OPENDATASOURCE(
'SQLOLEDB',
'Data Source=192.168.168.113;User ID=sa;Password=sa'
).ProductionMgr.dbo.D_User
declare @TGroupInfo table
(
[Grpid] [int],
[GroupName] [varchar](50)
)
insert into @TGroupInfo
select * from OPENDATASOURCE(
'SQLOLEDB',
'Data Source=192.168.168.116;User ID=sa;Password=sa'
).ProductionMgr.dbo.GroupInfo
declare @TUserAndGroup table
(
[UserId] [int],
[GrpId] [int]
)
insert into @TUserAndGroup
select * from OPENDATASOURCE(
'SQLOLEDB',
'Data Source=192.168.168.113;User ID=sa;Password=sa'
).ProductionMgr.dbo.UserAndGroup
select * from @TUser as u
inner join @TUserAndGroup as uag
on u.UserId=uag.UserId
inner join @TGroupInfo as g
on g.GrpId=uag.GrpId
--close
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
GO