Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have been trying to attempt this trigger. This doesn't seem to work. In this instance the program should turn the login attempts to 0 when the user in unblocked. Any suggestions please?

CREATE TRIGGER UserTrigger13
   ON  Users
   After update
AS 
DECLARE @Username nvarchar(50)
DECLARE @Num int


SET @Username = (SELECT Username FROM updated)
SET @Num = 0

UPDATE Users SET UserLoginAttempts = @Num WHERE UserBlocked = 0 AND Users.Username = @Username

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here

END
GO
Posted
Updated 17-May-12 1:21am
v2

Hi ,
Check This
By the way only trigger have the ability to get to deleted and inserted there is nothing called updated
SQL
CREATE TRIGGER UserTrigger13
   ON  Users
   After update
AS 
BEGIN
		DECLARE @Username nvarchar(50)
		DECLARE @Num int
		SET @Username = (SELECT Username FROM inserted)
		SET @Num = 0
 
			UPDATE Users SET UserLoginAttempts = @Num WHERE UserBlocked = 0 AND  Username = @Username
 
		BEGIN
			-- SET NOCOUNT ON added to prevent extra result sets from
			-- interfering with SELECT statements.
			SET NOCOUNT ON;
		 
			-- Insert statements for trigger here

		END
END

for reference http://msdn.microsoft.com/en-us/library/aa258254%28v=sql.80%29.aspx[^]
Best Regards
M.Mitwalli
 
Share this answer
 
v3
Comments
kim061 17-May-12 8:22am    
this is what was returned

Msg 8197, Level 16, State 4, Procedure TriggerUpdate, Line 6
The object 'Users' does not exist or is invalid for this operation.
Mohamed Mitwalli 17-May-12 9:04am    
I already execute the trigger and it work fine ,Just make sure Columns name is right
Best Regards
M.Mitwalli
kim061 17-May-12 9:07am    
it is right
Dev-0001 17-May-12 9:27am    
try this one
select @Username = ( select i.name FROM inserted i )
kim061 17-May-12 9:38am    
incorrect syntax near =
Try This link to understand Triggers:

http://sunandandutt.blogspot.com/2012/05/trigger.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900