Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2010-05-10 : 14:27:43
|
Trying to create a trigger that counts the records in a table that have a certain type and updates a field into the record that was just inserted. I know this code does not work, but I think it will give you an idea on what I'm trying to accomplish:CREATE TRIGGER [UpdateFreeField2] ON [dbo].[absences] AFTER insertASselect count(*) as xcountfrom absenceswhere absences.type = '501'update absencesset freenumberfield_02 = xcountfrom inserted join absences on inserted.ID = absences.ID |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-10 : 14:32:29
|
| [code]CREATE TRIGGER [UpdateFreeField2] ON [dbo].[absences] AFTER insertASupdate aset a.freenumberfield_02 = a1.xcountfrom absences ajoin inserted ion i.ID = a.IDjoin (select type,count(*) as xcount from absences group by type) a1on i.type = a1.typeand i.type='501'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|