473,395 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Trigger problem

10
Expand|Select|Wrap|Line Numbers
  1. SET QUOTED_IDENTIFIER ON 
  2. GO
  3. SET ANSI_NULLS ON 
  4. GO
  5.  
  6. ALTER  TRIGGER [Cust_Audit] ON [dbo].[Customer] 
  7. INSTEAD OF INSERT
  8. AS
  9.  
  10.     DECLARE @CustNum int 
  11.     DECLARE @CustomerCode INT,@CustomerIdentificationType INT
  12.     DECLARE @CustomerIdentificationGroupCode CHAR(50),@DocumentNumber CHAR(50)
  13.     DECLARE @FirstName CHAR(50),@LastName CHAR(50),@MiddleName CHAR(50)
  14.     DECLARE @CustomerName CHAR(50),@ContactPerson CHAR(75),@ContactTitle CHAR(50)
  15.     DECLARE @Country INT,@ParishOrState INT,@DistrictOrCity INT,@CommunityOrTownShip INT
  16.     DECLARE @Street CHAR(75),@TelephoneNumbers CHAR(50),@CellPhoneNumbers CHAR(50)
  17.     DECLARE @EmailAddress CHAR(50),@Photo Binary,@CustomerCategory INT
  18.     DECLARE @CustomerIdentificationIssuingInstitution CHAR(85)
  19.     DECLARE @CustomerIdentificationIssuingCountry INT,@CustomerIdentificationExpirationDate DATETIME
  20.     DECLARE @CustomerIdentificationCategory  CHAR(50),@Comments nvarchar(500),@Occupation CHAR(50),@DateofBirth DATETIME
  21.     DECLARE @TaxRegistrationNumber CHAR,@LastTradeDate DATETIME, @LastTradeValue FLOAT
  22.     DECLARE @LastTradeType CHAR(50),@TraderAssignedToAccount INT,@DiscountPuchaseTrade FLOAT
  23.     DECLARE @DiscountSaleTrade FLOAT,@MinimumPuchaseTradeValueForDiscount FLOAT
  24.     DECLARE @MinimumSaleTradeValueForDiscount FLOAT,@Active BIT,@CompanyCode INT,@LocationCode INT        
  25.     DECLARE @BranchCode INT,@OwnerCode INT,@DateTimeCreated DATETIME,@DateTimeModified DATETIME
  26.     DECLARE @CreatedByUser INT,@ModifiedByUser INT,@SourceOfFunds nvarchar(500)
  27.  
  28.     Set @CustNum =(Select cc.CustomerCode From Customer cc, inserted i WHERE cc.CustomerCode = i.CustomerCode)
  29.     BEGIN
  30.     SET @CustomerCode = (select customercode from inserted)
  31.     SET @CustomerIdentificationType = (select CustomerIdentificationType from inserted)
  32.     SET @CustomerIdentificationGroupCode = (select CustomerIdentificationGroupCode from inserted)
  33.     SET @DocumentNumber = (select DocumentNumber from inserted)
  34.     SET @FirstName = (select FirstName from inserted)
  35.     SET @LastName = (select LastName from inserted)
  36.     SET @MiddleName = (select MiddleName from inserted)
  37.     SET @CustomerName =(select CustomerName from inserted)
  38.     SET @ContactPerson = (select ContactPerson from inserted)
  39.     SET @ContactTitle =(select ContactTitle from inserted)
  40.     SET @Country = (select Country from inserted)
  41.     SET @ParishOrState=(select ParishOrState from inserted)
  42.     SET @DistrictOrCity=(select DistrictOrCity from inserted)
  43.     SET @CommunityOrTownShip =(select CommunityOrTownShip from inserted)
  44.     SET @Street = (select Street from inserted)
  45.     SET @TelephoneNumbers = (select TelephoneNumbers from inserted)
  46.     SET @CellPhoneNumbers = (select CellPhoneNumbers from inserted)
  47.     SET @EmailAddress =(select EmailAddress from inserted)
  48.     SET @Photo = (select cast(Photo as binary) from inserted)
  49.     SET @CustomerCategory = (select CustomerCategory from inserted)
  50.     SET @CustomerIdentificationIssuingInstitution = (select CustomerIdentificationIssuingInstitution from inserted)
  51.     SET @CustomerIdentificationIssuingCountry = (select CustomerIdentificationIssuingCountry from inserted)
  52.     SET @CustomerIdentificationExpirationDate =(select CustomerIdentificationExpirationDate from inserted)
  53.     SET @CustomerIdentificationCategory =  (select CustomerIdentificationCategory from inserted)
  54.     SET @Comments = (select cast(Comments as nvarchar(500)) from inserted)
  55.     SET @Occupation = (select Occupation from inserted)
  56.     SET @DateofBirth = (select DateOfBirth from inserted)
  57.     SET @TaxRegistrationNumber = (select TaxRegistrationNumber from inserted)
  58.     SET @LastTradeDate = (select LastTradeDate from inserted)
  59.     SET @LastTradeValue = (select LastTradeValue from inserted)
  60.     SET @LastTradeType = (select LastTradeType from inserted)
  61.     SET @TraderAssignedToAccount = (select LastTradeType from inserted)
  62.     SET @DiscountPuchaseTrade = (select DiscountPuchaseTrade from inserted)
  63.     SET @DiscountSaleTrade = (select DiscountSaleTrade from inserted)
  64.     SET @MinimumPuchaseTradeValueForDiscount = (select MinimumPuchaseTradeValueForDiscount from inserted)
  65.     SET @MinimumSaleTradeValueForDiscount = (select MinimumSaleTradeValueForDiscount from inserted)
  66.     SET @Active = (select Active from inserted)
  67.     SET @CompanyCode = (select CompanyCode from inserted)
  68.     SET @LocationCode = (select LocationCode from inserted)
  69.     SET @BranchCode = (select BranchCode from inserted)
  70.     SET @OwnerCode = (select OwnerCode from inserted)
  71.     SET @DateTimeCreated =(select DateTimeCreated from inserted)
  72.     SET @DateTimeModified =(select DateTimeModified from inserted)
  73.     SET @CreatedByUser = (select CreatedByUser from inserted)
  74.     SET @ModifiedByUser = (select ModifiedByUser  from inserted)
  75.     SET @SourceOfFunds = (select cast(SourceOfFunds as nvarchar(500)) from inserted)
  76.     END
  77.  
  78.     set nocount off
  79.     If ISNULL(@CustNum,'') =''
  80.  
  81.     BEGIN
  82.     INSERT INTO CUSTOMER(CustomerCode,CustomerIdentificationType ,
  83.     CustomerIdentificationGroupCode,DocumentNumber,
  84.     FirstName,LastName,MiddleName,
  85.     CustomerName,ContactPerson,ContactTitle,
  86.     Country,ParishOrState,DistrictOrCity,CommunityOrTownShip,
  87.     Street,TelephoneNumbers,CellPhoneNumbers,
  88.     EmailAddress,Photo,CustomerCategory,
  89.     CustomerIdentificationIssuingInstitution,
  90.     CustomerIdentificationIssuingCountry,CustomerIdentificationExpirationDate,
  91.     CustomerIdentificationCategory,Comments,Occupation,DateofBirth,
  92.     TaxRegistrationNumber,LastTradeDate, LastTradeValue,
  93.     LastTradeType,TraderAssignedToAccount,DiscountPuchaseTrade,
  94.     DiscountSaleTrade,MinimumPuchaseTradeValueForDiscount, 
  95.     MinimumSaleTradeValueForDiscount,Active,CompanyCode,LocationCode,        
  96.     BranchCode,OwnerCode,DateTimeCreated,DateTimeModified, 
  97.     CreatedByUser,ModifiedByUser,SourceOfFunds)
  98.     values(@CustomerCode,@CustomerIdentificationType,@CustomerIdentificationGroupCode,@DocumentNumber,
  99.     @FirstName,@LastName,@MiddleName,@CustomerName,@ContactPerson,@ContactTitle,
  100.     @Country,@ParishOrState,@DistrictOrCity,@CommunityOrTownShip,
  101.     @Street,@TelephoneNumbers,@CellPhoneNumbers,@EmailAddress,@Photo,@CustomerCategory,
  102.     @CustomerIdentificationIssuingInstitution,@CustomerIdentificationIssuingCountry,@CustomerIdentificationExpirationDate,
  103.     @CustomerIdentificationCategory,@Comments,@Occupation,@DateofBirth,
  104.     @TaxRegistrationNumber,@LastTradeDate, @LastTradeValue,
  105.     @LastTradeType,@TraderAssignedToAccount,@DiscountPuchaseTrade,
  106.     @DiscountSaleTrade,@MinimumPuchaseTradeValueForDiscount, 
  107.     @MinimumSaleTradeValueForDiscount,@Active,@CompanyCode,@LocationCode,
  108.     @BranchCode,@OwnerCode,@DateTimeCreated,@DateTimeModified,
  109.     @CreatedByUser,@ModifiedByUser,@SourceOfFunds) 
  110.     END
  111.     IF @@ROWCOUNT <> 0
  112.     BEGIN
  113.     INSERT INTO 
  114.         SysDatabase_Transactions( Record_Id,TableName,Operation,TransferDateTime)
  115.         Select b.CustomerCode,'Customer','I',Getdate()
  116.         From Inserted b
  117.     END
  118.     ELSE
  119.     BEGIN
  120.     UPDATE Customer
  121.     SET CustomerCode=@CustomerCode,CustomerIdentificationType=@CustomerIdentificationType ,
  122.     CustomerIdentificationGroupCode=@CustomerIdentificationGroupCode,DocumentNumber=@DocumentNumber,
  123.     FirstName=@FirstName,LastName=@LastName,MiddleName=@MiddleName,
  124.     CustomerName=@CustomerName,ContactPerson=@ContactPerson,ContactTitle=@ContactTitle,
  125.     Country=@Country,ParishOrState=@ParishOrState,DistrictOrCity=@DistrictOrCity,CommunityOrTownShip=@CommunityOrTownShip,
  126.     Street=@Street,TelephoneNumbers=@TelephoneNumbers,CellPhoneNumbers=@CellPhoneNumbers,
  127.     EmailAddress=@EmailAddress,Photo=@Photo,CustomerCategory=@CustomerCategory,
  128.     CustomerIdentificationIssuingInstitution=@CustomerIdentificationIssuingInstitution,
  129.     CustomerIdentificationIssuingCountry=@CustomerIdentificationIssuingCountry,CustomerIdentificationExpirationDate=@CustomerIdentificationExpirationDate,
  130.     CustomerIdentificationCategory=@CustomerIdentificationCategory,Comments=@Comments,Occupation=@Occupation,DateofBirth=@DateofBirth,
  131.     TaxRegistrationNumber=@TaxRegistrationNumber,LastTradeDate=@LastTradeDate,LastTradeValue=@LastTradeValue,
  132.     LastTradeType=@LastTradeType,TraderAssignedToAccount=@TraderAssignedToAccount,DiscountPuchaseTrade=@DiscountPuchaseTrade,
  133.     DiscountSaleTrade=@DiscountSaleTrade,MinimumPuchaseTradeValueForDiscount=@MinimumPuchaseTradeValueForDiscount, 
  134.     MinimumSaleTradeValueForDiscount=@MinimumSaleTradeValueForDiscount,Active=@Active,CompanyCode=@CompanyCode,LocationCode=@LocationCode,        
  135.     BranchCode=@BranchCode,OwnerCode=@OwnerCode,DateTimeCreated=@DateTimeCreated,DateTimeModified=@DateTimeModified, 
  136.     CreatedByUser=@CreatedByUser,ModifiedByUser=@ModifiedByUser,SourceOfFunds=@SourceOfFunds
  137.     WHERE CustomerCode = @CustNum
  138.     END
  139.     IF @@ROWCOUNT <> 0
  140.     BEGIN
  141.     INSERT INTO 
  142.         SysDatabase_Transactions( Record_Id,TableName,Operation,TransferDateTime)
  143.         Select b.CustomerCode,'Customer','U',Getdate()
  144.         From Inserted b
  145.     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
Feb 27 '08 #1
1 910
debasisdas
8,127 Expert 4TB
Sorry i don't have patience to read your code . Someone else might help you.
Feb 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Galina | last post by:
Hello I work with Oracle 9 database. I want to create a trigger using 2 tables: KEY_SKILLS_STUDENT and KEY_SKILLS. There are fields in KEY_SKILLS_STUDENT: KEY_SKILLS_ID, PORTFOLIO_RESULT and...
9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
13
by: Tolik Gusin | last post by:
Hello All, DB2 UDB 8.1 FP3 for Linux The table has 4 triggers on the Insert operation. Three triggers small (200 bytes) and one trigger large (3 ËÂ). In the large trigger there is one long...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
5
by: William of Ockham | last post by:
Hi, I was asked to recreate a new clean database for our developers because the current one they use is not entirely up to date. So I created a new database and I run into the followin strange...
2
by: gustavo_randich | last post by:
Hi :-) I'm porting a project from Oracle to DB2 and now I'm trying to avoid error SQL0746N in a trigger which reads the same table in which the trigger is defined. Below is Oracle's...
12
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
2
by: dean.cochrane | last post by:
I have inherited a large application. I have a table which contains a hierarchy, like this CREATE TABLE sample_table( sample_id int NOT NULL parent_sample_id int NOT NULL ....lots of other...
1
by: veasnamuch | last post by:
I have a problem while I create a trigger to my table. My objective is getting any change made to my table and record it in to another table . My have thousands records before I add new trigger to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.