Click to See Complete Forum and Search --> : Help Required for UPDATE TRIGGER


S2009
June 30th, 2009, 12:58 PM
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
--if(i.ReturnedOn is not null)
--begin
update nur
set nur.NumberOfBooksIssued = nur.NumberOfBooksIssued -1
from NewUserRegister nur inner join INSERTED i
on i.IssuedTo=nur.UserName and
i.ReturnedOn is not null
--end
set @Rows1 = @@RowCount
--if(i.ReturnedOn is not null)
--begin
update lbd set Inventory = Inventory +1
from LIBRARYBOOKDETAILS lbd inner join inserted i
on lbd.BookID = i.BookId and
i.ReturnedOn is not null
--end
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!!

binyo66
June 30th, 2009, 09:25 PM
What happen if u do
<code>
begin
if(i.ReturnedOn is null) THEN
begin tran
...
end trans
END IF
</code>