Help required for UPDATE TRIGGER

Reply

Join Date: Jun 2009
Posts: 67
Reputation: S2009 is an unknown quantity at this point 
Solved Threads: 0
S2009 S2009 is offline Offline
Junior Poster in Training

Help required for UPDATE TRIGGER

 
0
  #1
Jun 30th, 2009
Hi all,

I have created the Trigger for UPDATING to be invoked when Returnedon column is updated using the following code snnipet.

  1.  
  2. CREATE TRIGGER trg_ForUpdateOnBookIssuedDetails
  3. ON BOOKISSUEDDETAILS
  4. FOR UPDATE
  5. AS begin
  6. declare @Rows1 int,@Rows2 int
  7. IF(UPDATE(ReturnedOn))
  8.  
  9. begin
  10. begin tran
  11. UPDATE nur
  12. SET nur.NumberOfBooksIssued = nur.NumberOfBooksIssued -1
  13. FROM NewUserRegister nur INNER JOIN INSERTED i
  14. ON i.IssuedTo=nur.UserName
  15.  
  16. SET @Rows1 = @@RowCount
  17.  
  18. UPDATE lbd SET Inventory = Inventory +1
  19. FROM LIBRARYBOOKDETAILS lbd INNER JOIN
  20. inserted i ON lbd.BookID = i.BookId
  21.  
  22. SET @Rows2 = @@rowcount
  23.  
  24. IF @Rows1 * @rows2 >0
  25. commit tran
  26. else
  27. begin
  28. raiserror('Error Updating the Database',16,-1)
  29. rollback tran
  30. end
  31. end
  32. end
Now I want To perform this Updation only if the RETURNEDON column is null. If the ReturnedOn column consists of some other value then the Updation of records should not take place.

Can anyone help me out in performing this task?

Please help me out.

Thanks in advance!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 21
Reputation: NextCom is an unknown quantity at this point 
Solved Threads: 0
NextCom NextCom is offline Offline
Newbie Poster

Re: Help required for UPDATE TRIGGER

 
0
  #2
Jun 30th, 2009
Try to change:
if(update(ReturnedOn))
To:
IF (SELECT ReturnedOn FROM INSERTED) IS NULL
Last edited by peter_budo; Jul 2nd, 2009 at 4:55 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC