--查看当前连接情况
select * from sys.servers
--使用sp_helpserver显示可用的服务器
exec sp_helpserver
--删除已经存在的连接
exec sp_droplinkedsrvlogin 服务器别名,null
exec sp_dropserver 服务器别名
--使用
exec sp_addlinkedsrvlogin
'192.168.1.1' --被访问的服务器别名
'false',
'NULL',
'sa',--账号
'123123'--密码
select * from sys.servers
--使用sp_helpserver显示可用的服务器
exec sp_helpserver
--删除已经存在的连接
exec sp_droplinkedsrvlogin 服务器别名,null
exec sp_dropserver 服务器别名
--使用
exec sp_addlinkedsrvlogin
'192.168.1.1' --被访问的服务器别名
'false',
'NULL',
'sa',--账号
'123123'--密码
--插入(sqlserver----sqlserver)
insert openrowset('名称',‘ip地址’;‘数据库名’;‘数据库密码’;‘表名’,语句)
--查询
select * from openquery(DBLINK2ERP,'select * from cux_mes_erp_po_headers_iface');
select * from [192.168.1.1].[库名].dbo.表名
--删除
delete from openquery(DBLINK2ERP,'select * from cux_mes_erp_po_headers_iface');
select * from openquery(DBLINK2ERP,'select * from cux_mes_erp_po_headers_iface');
select * from [192.168.1.1].[库名].dbo.表名
--删除
delete from openquery(DBLINK2ERP,'select * from cux_mes_erp_po_headers_iface');
--DBLink 执行带有参数
--定义执行sql
declare @sql varchar(200);
set @sql=' select * from openquery(DBLINK2ERP,''select * from MES_USER.ERP_PO_L_FOR_MES where mes_po_num='''''+@number+''''''')';
exec(@sql)
--定义执行sql
declare @sql varchar(200);
set @sql=' select * from openquery(DBLINK2ERP,''select * from MES_USER.ERP_PO_L_FOR_MES where mes_po_num='''''+@number+''''''')';
exec(@sql)
----------------------------------------------------------------------------------------------------------------------------------------------------------
DBlink执行sql语句执行时,将sql语句写成一个字符串
declare @sql varchar(1000);
set @sql=' select * from openquery(DBLINK2ERP,''select * from MES_USER.ERP_PO_L_FOR_MES where MES_PO_NUM='''''+@number+''''''') ';
--采购接收对照视图回写到MES
INSERT INTO udt_mm_mes_erp_order exec(@sql)
set @sql=' select * from openquery(DBLINK2ERP,''select * from MES_USER.ERP_PO_L_FOR_MES where MES_PO_NUM='''''+@number+''''''') ';
--采购接收对照视图回写到MES
INSERT INTO udt_mm_mes_erp_order exec(@sql)
select * from openquery(LINK2ERP,'select * from cux_mes_erp_po_headers_iface order by po_number desc');
delete from openquery(LINK2ERP,'select * from cux_mes_erp_po_headers_iface where mes_po_number=''190702012'' ');
Hi,
Tomorrow!