Unanswered: Error in Trigger Using TRY CATCH AND IF ELSE
I am creating a trigger which should be triggered on insert to BOOKISSUEDETAILS table. I want to alter the table LIBRARYBOOKDETAILS table only if the Inventory column value is greater than 1.
Initially I have created the trigger in the following way. But now I want to alter the Trigger to include the condition(Inventory > 1) and use the Try catch block to raise error.
I used the following code snippet to alter the trigger, but it is generating the error:
alter trigger trg_InsertInBookIssuedDetails on BOOKISSUEDDETAILS
select @UserName = IssuedTo,@BookID = BookID from BOOKISSUEDDETAILS
update NewUserRegister set NumberOfBooksIssued = NumberOfBooksIssued+1 where UserName = @UserName
if (select Inventory from LIBRARYBOOKDETAILS WHERE BookID = @BookID)>1
update LIBRARYBOOKDETAILS set Inventory = Inventory - 1 where BookID= @BookID
raiserror('Books UnAvailable Or Cannot Issue More Than 3 Books',16,-1)
Msg 156, Level 15, State 1, Procedure trg_InsertInBookIssuedDetails, Line 19
Incorrect syntax near the keyword 'else'.
Msg 156, Level 15, State 1, Procedure trg_InsertInBookIssuedDetails, Line 25
Incorrect syntax near the keyword 'end'.
Can anyone let me know the error? and the changes I should make to perform the desired task with condition.