Server1:
DB Version: 2012
Server IP: 192.168.120.252
Souce Database
Server2:
DB Version: 2012
Server IP: 192.168.120.210
Target Database
在Server2上执行以下语句
exec sp_addlinkedserver 'sqlserver', '', 'SQLOLEDB', '192.168.120.252'exec sp_addlinkedsrvlogin 'sqlserver', 'false',null, 'sa', ''
go
SELECT *
FROM
OPENROWSET('SQLOLEDB',
'server=192.168.120.252uid=sapwd=XXXXX', --字符串
DBName.dbo.TableName) --直接写表的名称
需要变通一下,希望对你有帮助!--sql-开始--------------
declare @row_limit int
set @row_limit=10
declare @sql NVARCHAR(1000)
set @sql='SELECT top '+cast(@row_limit as NVARCHAR(20))
+' [StoreID],[OrderNumber],[ShipmentID] '
+' FROM [192.168.1.254].[YY_Integration].[dbo].[Shipments] with(nolock) '
+' where storeid in (5,9) and [PrintedOn]>''2010-09-01'''
exec SP_EXECUTESQL @sql
--sql-结束--------------
可以创建链接服务器,然后使用链接服务器的方式连接到远程数据库,SQL语句语法格式如下:SELECT * FROM [链接服务器名称].[数据库名称].[dbo].[表名]
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)