Use SQLServer triggers

Creating a trigger

The CREATE  TRIGGER Decor - Trigger Name 
   the ON dbo.SG_DecorationEntry - table 
   an AFTER the INSERT  - operations (additions and deletions) 
the AS  
the BEGIN 
    the DECLARE  @id  the UNIQUEIDENTIFIER  
    the SELECT  @id = Inserted.DecorationEntryID the FROM the Inserted - data add operation 
    - requires business execution of 
    INSERT  INTO dbo.SG_DecorationEntryAPLog 
            (DecorationEntryAPLogID, 
              DecorationEntryID, 
              ApprovalAction, 
              ApprovalUser,  
              ApprovalDate,
              ApprovalOpinion,
              ApprovalUserCode
            )
    VALUES  ( NEWID() , -- DecorationEntryAPLogID - uniqueidentifier
              @id , -- DecorationEntryID - uniqueidentifier
              N'' , -- ApprovalAction - nvarchar(50)
              N'' , -- ApprovalUser - nvarchar(50)
              GETDATE() , -- ApprovalDate - datetime
              N'' , -- ApprovalOpinion - nvarchar(1000)
              N''  -- ApprovalUserCode - nvarchar(50)
            )


END

You can also call the interface in a trigger

The CREATE  TRIGGER Decor
 the ON dbo.SG_DecorationEntry 
an AFTER the INSERT  
the AS  
the BEGIN 

DECLARE  @ServiceUrl  AS  VARCHAR ( 1000 ) 
 DECLARE  @UrlAddress  VARCHAR ( 500 )
 - the WebService Address: beginning with http, ending with a slash, e.g. 'http: //webservice.webxml. com.cn/WebServices/MobileCodeWS.asmx/ ' 
SET  @UrlAddress  =  ' .... ' 
DECLARE  @FunName  VARCHAR ( 50 )
 - a method called WebService names: for example' getMobileCodeInfo ' 
SET  @FunName  = ' GetEntryAndExitData '  
- following parameters corresponding to [parameter name] in the WebService four parameters 
DECLARE  @ Pl  VARCHAR ( 100 ), @ P2  VARCHAR ( 100 )
 SET  @ Pl  =  ' Data ' 
SET  @ P2  =  ' the userid ' 
DECLARE  @ P1_Value  VARCHAR ( max ), @ P2_Value  VARCHAR ( 800 )
 SET  @ P1_Value  =  ' { "OrganizationID": "BDA02110-39BF-48CE-8D00-E4D31A45EE88"} ' 
SET @P2_Value = ''
set @ServiceUrl = @UrlAddress + @FunName + '?' + @P1 + '=' + @P1_Value 
Declare @Object as Int
Declare @ResponseText as Varchar(8000)

Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'get',@ServiceUrl,'false'
Exec sp_OAMethod @Object, 'send'
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

Select @ResponseText 
Exec sp_OADestroy @Object


END

 

Guess you like

Origin www.cnblogs.com/heyiping/p/11512961.html