Hmm, I notice that you stated, but did not actually set a value for your variables in your else statement, this could cause SQL not to insert what you expected. Oddly enough, I need to do the same in the task at the moment, here is my solution:
CREATE TRIGGER instead_of_insert ON Question4 INSTEAD OF INSERT AS Declare @Username varchar(25) Declare @Question varchar(6) Declare @Answer char(1) Set @Username ='John' IF (Select UserName from inserted) = @UserName Begin RAISERROR ('You have not paid up your fee', 10,1) End Else Begin Set @Username = (Select UserName from inserted) Set @Question = (Select Question_ID from inserted) Set @Answer = (Select Answer from inserted) Insert into User_Responses Values (@username, @Question, @Answer) End
source share