DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   MS SQL (http://www.daniweb.com/forums/forum127.html)
-   -   Help required for UPDATE TRIGGER (http://www.daniweb.com/forums/thread200706.html)

S2009 Jun 30th, 2009 10:36 am
Help required for UPDATE TRIGGER
 
Hi all,

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


CREATE TRIGGER trg_ForUpdateOnBookIssuedDetails
on BOOKISSUEDDETAILS
For update
as begin
declare @Rows1 int,@Rows2 int
if(update(ReturnedOn))

begin
begin tran
update nur
set nur.NumberOfBooksIssued = nur.NumberOfBooksIssued -1
from NewUserRegister nur inner join INSERTED i
on i.IssuedTo=nur.UserName

set @Rows1 = @@RowCount

update lbd set Inventory = Inventory +1
from LIBRARYBOOKDETAILS lbd inner join
inserted i on lbd.BookID = i.BookId

set @Rows2 = @@rowcount

if @Rows1 * @rows2 >0
commit tran
else
begin
raiserror('Error Updating the Database',16,-1)
rollback tran
end
end
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!!

NextCom Jun 30th, 2009 2:55 pm
Re: Help required for UPDATE TRIGGER
 
Try to change:
if(update(ReturnedOn))

To:
IF (SELECT ReturnedOn FROM INSERTED) IS NULL


All times are GMT -4. The time now is 7:15 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC