1、使用游标实现跨数据库导数据
参考存储过程:
ALTER proc [dbo].[Nsp_SiPingElectricityData]
as
declare @DANo Char(32)
declare @DATime Datetime
declare @LogTime Datetime
declare @MeterType Char(4)
declare @MeterNo Char(20)
declare @Qty Decimal(18,6)
declare @tagname nvarchar(50)
declare @sql nvarchar(800)
declare convertCursor cursor for
select replace(replace(replace(replace(convert(nvarchar(25),getdate(),121),'-',''),' ',''),':',''),'.',''),
b.tagname,b.PValue ,b.date_time a,b.date_time ,'EM' ,bb.meterno
from openrowset('SQLOLEDB','10.30.16.182';'sa';'tjdx',tj_siping2.dbo.Substation_siping) b,SiPingElectricityMeter bb
where
b.PValue>0
and
b.tagname=bb.TagNameNew
and
(b.label is null or b.label=0)
and b.Date_time is not null
order by b.Date_time asc
open convertCursor
fetch next from convertCursor into @DANo,@tagname,@QTY,@DATime,@LogTime,@MeterType,@meterno
while @@FETCH_STATUS=0
begin
begin
insert into SiPingElectricityD