Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update Trigger

Author  Topic 

rmrper99
Starting Member

29 Posts

Posted - 2006-05-24 : 21:42:24
I am new to triggers and I have read BOL but I don't understand.

What I am trying to do I think is rather simple. If the STATUS field changes to R, then I want to update that record by putting "rejected" in the USER1 field.

Can someone help me?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-24 : 21:45:31
Place this in your update trigger
update u
set USER1 = 'rejected'
from inserted i inner join table u
on i.pk = u.pk
where i.STATUS = 'R'



KH

Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-05-24 : 22:37:40
why not do the update of user1 in your update query instead?



--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-25 : 04:10:45
If R stands for Rejected, then no need of updating it. In select statement use

Select columns, case when User1='R' then 'Rejected' end from yourTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-25 : 04:43:44
adjusting minor typo err
Select columns, case when User1 STATUS = 'R' then 'Rejected' end as USER1 from yourTable



KH

Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2006-05-25 : 04:58:35
If you use that approach, then you should probably catch the rest of the possibilities -

Select columns, case when STATUS = 'R' then 'Rejected' else user1 end as USER1 from yourTable



-------
Moo. :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-25 : 05:14:12
quote:
Originally posted by khtan

adjusting minor typo err
Select columns, case when User1 STATUS = 'R' then 'Rejected' end as USER1 from yourTable



KH




Thanks for the correction

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -