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

Trigger an update field on the same inserted table?

Status
Not open for further replies.

fredong

IS-IT--Management
Sep 19, 2001
332
US
Hi,
I have a table name AA and I need to update a field name 'Priority' in the AA table using trigger when a row is inserted to the AA table. Is that possible? Thanks

Priority 1,2,3, or 4






AA Table

Num OrderNum Salesperson Date Priority
--- -------- ---------- ---- --------
1 0001 Peter 1/1/2007 (I need an update)
2 0002 John 1/2/2007 (I need an update)
3 0003 James 1/3/2007 (I need an update)
 
what value do you need? If there is one default value all new records would get, it is better to do it using a defined default on the field rather than in a trigger. othrewise we would need to know what logic determines the priority to help you.

Questions about posting. See faq183-874
 
The value is based on the Date entered and compared to getdate()

For example the date entered is less than 1 hour than getdate() is priority 1 and less than 2 hours is 2 and less than 3 hours is 3 and so forth
 
That seems very simple. wouldn't a derived column work better than a trigger?

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
There is a computed column specification property in you table properties. You can put something like this in there.
Code:
SELECT DATEDIFF(hh, Date, getdate())

I've never used this but I know if can be done. Check BOL.

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top