Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to update field in one table using after insert trigger..? Expand / Collapse
Author
Message
Posted Monday, September 1, 2008 7:28 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 20, 2013 6:07 AM
Points: 78, 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
Post #561995
Posted Monday, September 1, 2008 11:10 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 12:40 AM
Points: 7,001, Visits: 8,439
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


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- 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"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #562067
Posted Tuesday, September 2, 2008 12:44 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 20, 2013 6:07 AM
Points: 78, Visits: 171
Thanks a lot :)
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
Post #562216
Posted Tuesday, September 2, 2008 5:05 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 12:40 AM
Points: 7,001, Visits: 8,439
sanjeev_krs2004 (9/2/2008)
Thanks a lot :)
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


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- 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"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #562310
Posted Tuesday, September 2, 2008 7:18 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 20, 2013 6:07 AM
Points: 78, Visits: 171
Thanks a lot :D

It solved my problem.

Thanks
Post #562373
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse