Expand|Select|Wrap|Line Numbers
- SET QUOTED_IDENTIFIER ON
- GO
- SET ANSI_NULLS ON
- GO
- ALTER TRIGGER [Cust_Audit] ON [dbo].[Customer]
- INSTEAD OF INSERT
- AS
- DECLARE @CustNum int
- DECLARE @CustomerCode INT,@CustomerIdentificationType INT
- DECLARE @CustomerIdentificationGroupCode CHAR(50),@DocumentNumber CHAR(50)
- DECLARE @FirstName CHAR(50),@LastName CHAR(50),@MiddleName CHAR(50)
- DECLARE @CustomerName CHAR(50),@ContactPerson CHAR(75),@ContactTitle CHAR(50)
- DECLARE @Country INT,@ParishOrState INT,@DistrictOrCity INT,@CommunityOrTownShip INT
- DECLARE @Street CHAR(75),@TelephoneNumbers CHAR(50),@CellPhoneNumbers CHAR(50)
- DECLARE @EmailAddress CHAR(50),@Photo Binary,@CustomerCategory INT
- DECLARE @CustomerIdentificationIssuingInstitution CHAR(85)
- DECLARE @CustomerIdentificationIssuingCountry INT,@CustomerIdentificationExpirationDate DATETIME
- DECLARE @CustomerIdentificationCategory CHAR(50),@Comments nvarchar(500),@Occupation CHAR(50),@DateofBirth DATETIME
- DECLARE @TaxRegistrationNumber CHAR,@LastTradeDate DATETIME, @LastTradeValue FLOAT
- DECLARE @LastTradeType CHAR(50),@TraderAssignedToAccount INT,@DiscountPuchaseTrade FLOAT
- DECLARE @DiscountSaleTrade FLOAT,@MinimumPuchaseTradeValueForDiscount FLOAT
- DECLARE @MinimumSaleTradeValueForDiscount FLOAT,@Active BIT,@CompanyCode INT,@LocationCode INT
- DECLARE @BranchCode INT,@OwnerCode INT,@DateTimeCreated DATETIME,@DateTimeModified DATETIME
- DECLARE @CreatedByUser INT,@ModifiedByUser INT,@SourceOfFunds nvarchar(500)
- Set @CustNum =(Select cc.CustomerCode From Customer cc, inserted i WHERE cc.CustomerCode = i.CustomerCode)
- BEGIN
- SET @CustomerCode = (select customercode from inserted)
- SET @CustomerIdentificationType = (select CustomerIdentificationType from inserted)
- SET @CustomerIdentificationGroupCode = (select CustomerIdentificationGroupCode from inserted)
- SET @DocumentNumber = (select DocumentNumber from inserted)
- SET @FirstName = (select FirstName from inserted)
- SET @LastName = (select LastName from inserted)
- SET @MiddleName = (select MiddleName from inserted)
- SET @CustomerName =(select CustomerName from inserted)
- SET @ContactPerson = (select ContactPerson from inserted)
- SET @ContactTitle =(select ContactTitle from inserted)
- SET @Country = (select Country from inserted)
- SET @ParishOrState=(select ParishOrState from inserted)
- SET @DistrictOrCity=(select DistrictOrCity from inserted)
- SET @CommunityOrTownShip =(select CommunityOrTownShip from inserted)
- SET @Street = (select Street from inserted)
- SET @TelephoneNumbers = (select TelephoneNumbers from inserted)
- SET @CellPhoneNumbers = (select CellPhoneNumbers from inserted)
- SET @EmailAddress =(select EmailAddress from inserted)
- SET @Photo = (select cast(Photo as binary) from inserted)
- SET @CustomerCategory = (select CustomerCategory from inserted)
- SET @CustomerIdentificationIssuingInstitution = (select CustomerIdentificationIssuingInstitution from inserted)
- SET @CustomerIdentificationIssuingCountry = (select CustomerIdentificationIssuingCountry from inserted)
- SET @CustomerIdentificationExpirationDate =(select CustomerIdentificationExpirationDate from inserted)
- SET @CustomerIdentificationCategory = (select CustomerIdentificationCategory from inserted)
- SET @Comments = (select cast(Comments as nvarchar(500)) from inserted)
- SET @Occupation = (select Occupation from inserted)
- SET @DateofBirth = (select DateOfBirth from inserted)
- SET @TaxRegistrationNumber = (select TaxRegistrationNumber from inserted)
- SET @LastTradeDate = (select LastTradeDate from inserted)
- SET @LastTradeValue = (select LastTradeValue from inserted)
- SET @LastTradeType = (select LastTradeType from inserted)
- SET @TraderAssignedToAccount = (select LastTradeType from inserted)
- SET @DiscountPuchaseTrade = (select DiscountPuchaseTrade from inserted)
- SET @DiscountSaleTrade = (select DiscountSaleTrade from inserted)
- SET @MinimumPuchaseTradeValueForDiscount = (select MinimumPuchaseTradeValueForDiscount from inserted)
- SET @MinimumSaleTradeValueForDiscount = (select MinimumSaleTradeValueForDiscount from inserted)
- SET @Active = (select Active from inserted)
- SET @CompanyCode = (select CompanyCode from inserted)
- SET @LocationCode = (select LocationCode from inserted)
- SET @BranchCode = (select BranchCode from inserted)
- SET @OwnerCode = (select OwnerCode from inserted)
- SET @DateTimeCreated =(select DateTimeCreated from inserted)
- SET @DateTimeModified =(select DateTimeModified from inserted)
- SET @CreatedByUser = (select CreatedByUser from inserted)
- SET @ModifiedByUser = (select ModifiedByUser from inserted)
- SET @SourceOfFunds = (select cast(SourceOfFunds as nvarchar(500)) from inserted)
- END
- set nocount off
- If ISNULL(@CustNum,'') =''
- BEGIN
- INSERT INTO CUSTOMER(CustomerCode,CustomerIdentificationType ,
- CustomerIdentificationGroupCode,DocumentNumber,
- FirstName,LastName,MiddleName,
- CustomerName,ContactPerson,ContactTitle,
- Country,ParishOrState,DistrictOrCity,CommunityOrTownShip,
- Street,TelephoneNumbers,CellPhoneNumbers,
- EmailAddress,Photo,CustomerCategory,
- CustomerIdentificationIssuingInstitution,
- CustomerIdentificationIssuingCountry,CustomerIdentificationExpirationDate,
- CustomerIdentificationCategory,Comments,Occupation,DateofBirth,
- TaxRegistrationNumber,LastTradeDate, LastTradeValue,
- LastTradeType,TraderAssignedToAccount,DiscountPuchaseTrade,
- DiscountSaleTrade,MinimumPuchaseTradeValueForDiscount,
- MinimumSaleTradeValueForDiscount,Active,CompanyCode,LocationCode,
- BranchCode,OwnerCode,DateTimeCreated,DateTimeModified,
- CreatedByUser,ModifiedByUser,SourceOfFunds)
- values(@CustomerCode,@CustomerIdentificationType,@CustomerIdentificationGroupCode,@DocumentNumber,
- @FirstName,@LastName,@MiddleName,@CustomerName,@ContactPerson,@ContactTitle,
- @Country,@ParishOrState,@DistrictOrCity,@CommunityOrTownShip,
- @Street,@TelephoneNumbers,@CellPhoneNumbers,@EmailAddress,@Photo,@CustomerCategory,
- @CustomerIdentificationIssuingInstitution,@CustomerIdentificationIssuingCountry,@CustomerIdentificationExpirationDate,
- @CustomerIdentificationCategory,@Comments,@Occupation,@DateofBirth,
- @TaxRegistrationNumber,@LastTradeDate, @LastTradeValue,
- @LastTradeType,@TraderAssignedToAccount,@DiscountPuchaseTrade,
- @DiscountSaleTrade,@MinimumPuchaseTradeValueForDiscount,
- @MinimumSaleTradeValueForDiscount,@Active,@CompanyCode,@LocationCode,
- @BranchCode,@OwnerCode,@DateTimeCreated,@DateTimeModified,
- @CreatedByUser,@ModifiedByUser,@SourceOfFunds)
- END
- IF @@ROWCOUNT <> 0
- BEGIN
- INSERT INTO
- SysDatabase_Transactions( Record_Id,TableName,Operation,TransferDateTime)
- Select b.CustomerCode,'Customer','I',Getdate()
- From Inserted b
- END
- ELSE
- BEGIN
- UPDATE Customer
- SET CustomerCode=@CustomerCode,CustomerIdentificationType=@CustomerIdentificationType ,
- CustomerIdentificationGroupCode=@CustomerIdentificationGroupCode,DocumentNumber=@DocumentNumber,
- FirstName=@FirstName,LastName=@LastName,MiddleName=@MiddleName,
- CustomerName=@CustomerName,ContactPerson=@ContactPerson,ContactTitle=@ContactTitle,
- Country=@Country,ParishOrState=@ParishOrState,DistrictOrCity=@DistrictOrCity,CommunityOrTownShip=@CommunityOrTownShip,
- Street=@Street,TelephoneNumbers=@TelephoneNumbers,CellPhoneNumbers=@CellPhoneNumbers,
- EmailAddress=@EmailAddress,Photo=@Photo,CustomerCategory=@CustomerCategory,
- CustomerIdentificationIssuingInstitution=@CustomerIdentificationIssuingInstitution,
- CustomerIdentificationIssuingCountry=@CustomerIdentificationIssuingCountry,CustomerIdentificationExpirationDate=@CustomerIdentificationExpirationDate,
- CustomerIdentificationCategory=@CustomerIdentificationCategory,Comments=@Comments,Occupation=@Occupation,DateofBirth=@DateofBirth,
- TaxRegistrationNumber=@TaxRegistrationNumber,LastTradeDate=@LastTradeDate,LastTradeValue=@LastTradeValue,
- LastTradeType=@LastTradeType,TraderAssignedToAccount=@TraderAssignedToAccount,DiscountPuchaseTrade=@DiscountPuchaseTrade,
- DiscountSaleTrade=@DiscountSaleTrade,MinimumPuchaseTradeValueForDiscount=@MinimumPuchaseTradeValueForDiscount,
- MinimumSaleTradeValueForDiscount=@MinimumSaleTradeValueForDiscount,Active=@Active,CompanyCode=@CompanyCode,LocationCode=@LocationCode,
- BranchCode=@BranchCode,OwnerCode=@OwnerCode,DateTimeCreated=@DateTimeCreated,DateTimeModified=@DateTimeModified,
- CreatedByUser=@CreatedByUser,ModifiedByUser=@ModifiedByUser,SourceOfFunds=@SourceOfFunds
- WHERE CustomerCode = @CustNum
- END
- IF @@ROWCOUNT <> 0
- BEGIN
- INSERT INTO
- SysDatabase_Transactions( Record_Id,TableName,Operation,TransferDateTime)
- Select b.CustomerCode,'Customer','U',Getdate()
- From Inserted b
- END
The above code is within my trigger. The problem is that nothing is been inserted in the SysDatabase_Transaction table. Can someone tell me what i be doing wrong
Thanks in advance