Click here to Skip to main content
15,909,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have StatusMaster table, which has column called status

I want to run some utility whenever status becomes 'SUCCESS'

I think trigger is the best solution for it.
So i want one trigger on update, which will get triggered whenever status becomes success.

Thanks in Advance.
Posted

Hi,

Yes a trigger sounds appropriate.

Here's a good introduction article to triggers in SQL.

http://www.sqlteam.com/article/an-introduction-to-triggers-part-i[^]
 
Share this answer
 
Hi Friend,
Hope this will help you.

SQL
CREATE trigger TrginsertStatusMaster on StatusMaster
for update
as 
--write the code as per your requirement
--insert INTO emp (name) VALUES ('Satype')


[edit]Code block added[/edit]
 
Share this answer
 
v2
SQL
create trigger trgafterupdate on dbo.Employee_Test
for update
as declare @emp_id int;
 declare @emp_name nvarchar(50);
 declare @emp_sal decimal(10,2);
 declare @status nvarchar(50);

 select @status=i.status from inserted i;

 if(@status='SUCCESS')
 begin
  print 'abc';//on true condition  code here 
  end
  else
  print 'andd';// on false condition code here


In trigger body ,table named inserted has been used .this table is a logical table and contains the row that has been updated

[edit]Code block fixed[/edit]
 
Share this answer
 
v2
Comments
sunil mali 26-Jun-13 3:46am    
Thank you so much sir...
INSTEAD OF UPDATE Trigger

SQL
CREATE TRIGGER trgInsteadOfDelete ON [dbo].[Employee_Test] 
INSTEAD OF UPDATE
AS
	declare @status bit;	
	select @status =u.Status from updated u;
	
	BEGIN
		if(@status > 0)
		begin
			--do ur stuff here
		end		
	END
GO
 
Share this answer
 
Comments
sunil mali 26-Jun-13 3:46am    
Thank you so much sir..

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