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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger to update a field

Status
Not open for further replies.

TheBigD

Programmer
Sep 12, 2000
10
0
0
US
I have a field called time, the format is 4:30. I want to convert it to 270 minutes which I would store in the field timeminutes.

I am trying to write a trigger that when the record is inserted or updated the timeminute field would be updated with the correct minutes.

Thanks,
Dennis
 
Here is an example.
[tt]
Create Trigger trg_Insert On yourtable
For update, insert
As

If Update([Time])
Begin
Update yourtable
Set timeminute=datediff(n,'0:00',[Time])
From yourtable t
Join inserted i
On t.KeyCol=i.KeyCol
End[/tt]

I recommend that you avoid using reserved words such as Time for column or object names. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top