Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creting triggers

Status
Not open for further replies.

Greg25

Technical User
May 30, 2001
159
US
First i should say that i am not a programer.

But have set up a sql server 7 for the company i work for. I need to creat two triggers

one, when the status of one field is changed, would like to produce the date of the update in another field

two, when an invoice is created I would like to produce the current date plus the terms (ex.net 30 , net 10 ).

i would be very greatfull

thanks
Greg sales@magprint.com
 
CREATE TRIGGER mytriggername ON dbo.mytable
FOR UPDATE
AS
if update(myfield)
begin
update mytable set mydate = getdate()
from mytable, inserted
where mytable.primarykeyfield = inserted.primarykeyfield
end

Create Trigger mytiggername2 on dbo.invoices
for insert
as
update invoices set mydate = dateadd(day,terms,getdate())
from invoices, inserted where
invoices.primarykey = inserted.primarykey

This assumes that you have a terms field that is numeric, if not you will have to do some additional work. Get a manual and work it out.

Also in the future please post the following as part of your question.

What version of SQL server you are using, basic table layouts so we have your field names, types and keys

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top