日期:2014-05-17 浏览次数:20772 次
--创建远程同步连接
IF not exists(select 1 from master.dbo.sysservers where srvname = 'shangluoqixiang')
BEGIN
EXEC sp_addlinkedserver 'shangluoqixiang', ' ', 'SQLOLEDB', '127.0.0.1'--这一行需要根据实际情况修改 IP
EXEC sp_addlinkedsrvlogin 'shangluoqixiang', 'false',null, 'sa', 'password'--这一行需要根据实际情况修改 密码
print ' 数据库远程联接创建成功!';
END
ELSE
exec sp_dropserver 'shangluoqixiang', 'droplogins'
EXEC sp_addlinkedserver 'shangluoqixiang', ' ', 'SQLOLEDB', '127.0.0.1'--这一行需要根据实际情况修改 IP
EXEC sp_addlinkedsrvlogin 'shangluoqixiang', 'false',null, 'sa', 'password' --这一行需要根据实际情况修改 密码
print '数据库远程联接创建成功!';
GO
create TRIGGER [dbo].[trigger_MsgMediumSmallScale_insert]
on [dbo].[QX_MsgMediumSmallScaleTemp]
--on MsgMediumSmallScale
FOR INSERT
AS
--在事务开始前加入set xact_abort ON语句
SET XACT_ABORT ON
--定义变量
DECLARE @stcd varchar(8);
DECLARE @rain int,@stid int;
DECLARE @DateChar datetime,@tm datetime;
DECLARE @TimeChar nchar(4)
DECLARE @hour int
set @stid=1;--这一行需要根据实际情况修改 没有确定
DECLARE @countNo int;
--INSERT trigger
select @countNo =count(StationID) from inserted;
print @countNo +'2244'
if(@countNo=1)
begin
SELECT @stcd=StationID, @DateChar=DateChar , @TimeChar=TimeChar, @rain =Rain from inserted;
-- set @hour=CONVERT(int, @TimeChar,2)
-- set @tm =dateadd(hh,CONVERT(int, @TimeChar,2),@DateChar)
set @tm =@DateChar
INSERT INTO shangluoqixiang.[shanyang].[dbo].[st_pptn_r]([stid] ,[tm] ,[intv],[pdr],[dyp],[drp],[wth],[stcd])
VALUES
(1,'2013-04-15',1 ,null,1,null ,null ,'88')
end