SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to update field in one table using after insert trigger..?


How to update field in one table using after insert trigger..?

Author
Message
sanjeev_krs2004
sanjeev_krs2004
SSC-Enthusiastic
SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)

Group: General Forum Members
Points: 124 Visits: 171
Hi,
I have two tables namely account and invoice.
I want to update one field in account table when there is A NEW RECORD inserted in invoice table. I want to use only triggers nothing else.

Thanks
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12103 Visits: 8924
sanjeev_krs2004 (9/1/2008)
Hi,
I have two tables namely account and invoice.
I want to update one field in account table when there is A NEW RECORD inserted in invoice table. I want to use only triggers nothing else.

Thanks

If this is your most optimal way, I cannot tell, but if you insist on using a trigger...



Create trigger utr_I_Invoice on dbo.invoice
for insert
as
update A
set yourcol=yourcol + whatever
from dbo.account A
inner join inserted I
on A.account_id = I.Invoice_Account_Id




Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
sanjeev_krs2004
sanjeev_krs2004
SSC-Enthusiastic
SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)

Group: General Forum Members
Points: 124 Visits: 171
Thanks a lot Smile
I got it; could you please tell me how to use for loop if I need to pick up one of the different lookup (drop-down) values.

for example, I want to update the flag to true in account table. but before updating the value I must compare one field (say id) with the one in another table but is in lookup format means you can select one value from the drop down.

Thanks
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12103 Visits: 8924
sanjeev_krs2004 (9/2/2008)
Thanks a lot Smile
I got it; could you please tell me how to use for loop if I need to pick up one of the different lookup (drop-down) values.

for example, I want to update the flag to true in account table. but before updating the value I must compare one field (say id) with the one in another table but is in lookup format means you can select one value from the drop down.

Thanks

euhm ... there is no "dropdown" in sqlserver.
The only thing you have is a set of rows (from a table, view, ..)

just add an extra

and exists (select * from your_lookup_table LT where LT.id = I.id)




Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
sanjeev_krs2004
sanjeev_krs2004
SSC-Enthusiastic
SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)SSC-Enthusiastic (124 reputation)

Group: General Forum Members
Points: 124 Visits: 171
Thanks a lot BigGrin

It solved my problem.

Thanks
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search