一,首先创建链接语句
--exec sp_addlinkedserver ‘名称’,'','SQLOLEDB','无服务器地址'
--exec sp_addlinkedsrvlogin '名称','false',null,'账号','密码'
--go
2,当直接使用查询的联合语句后发现会出现异常信息:
cannot resolve the collation conflict between "chinese_prc_ci_as" and "sql_latin1_general_cp1_ci_as" in the equal to operation
解决方法:
先将一个服务器上查的信息存储到零时表中,之后再联合另一个服务器
create table #constrat
(
pono nvarchar(50),
applyuser nvarchar(30),
conno nvarchar(50),
btime datetime,
etime datetime
)
insert into #constrat
SELECT
t2.pono
,t1.[C_People] as 申请人
,t1.[CNO] as 合同编号
,t4.[B_DATETIME] AS 申请日期
,t4.[E_DATETIME] as 审核结束时间
--,t3.fa_return_time as PO生效日期
FROM [MROPRDB].[dbo].[C_Contract_List] t1,[MROPRDB].[dbo].[C_PO_List] t2 ,[SPM].[dbo].[CASES] t4
where month(t1.C_Time)>5 and month(t1.C_time)<10 and year(t1.c_Time)=2013
and t1.C_Number=t2.txtNO and t1.C_CaseId=t4.caseid
select t1.applyuser 申请人,t1.conno 合同编号,t1.btime 申请时间,t1.etime 审批结束时间,t2.fa_return_time PO生效日期 from #constrat t1,potime.MRO.dbo.OrderInfo t2
where t1.pono=t2.order_no and t2.status='3'
exec sp_dropserver '名称','droplogins'