•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 373,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,612 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 671 | Replies: 6
![]() |
•
•
Join Date: Dec 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I have a simple SQL query
It updates 114 records
I am trying to write a trigger that will change a flag to 1 for all record updated by the query.
THe problem is the trigger is updating 214 records and they appear to have no relation to the join.
The 3 columns below are statusid, grade and iscounted
You can see the grade updated correctly then the trigger updated extra records. Any idea why?
I have a simple SQL query
sql Syntax (Toggle Plain Text)
UPDATE testcourselog SET grade='a' WHERE statusid=4
I am trying to write a trigger that will change a flag to 1 for all record updated by the query.
sql Syntax (Toggle Plain Text)
USE [online] GO /****** Object: Trigger [dbo].[gl_courselog_iscounted_update] Script Date: 12/10/2007 16:49:32 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= ALTER TRIGGER [dbo].[gl_courselog_iscounted_update] ON [dbo].[testcourselog] AFTER INSERT,UPDATE AS IF UPDATE(grade) AND (SELECT count(*) FROM inserted) > 0 BEGIN IF @@ROWCOUNT = 1 BEGIN SET NOCOUNT ON; UPDATE testcourselog SET iscounted=1 WHERE userid=(SELECT userid FROM inserted) END ELSE BEGIN UPDATE testcourselog SET iscounted=1 FROM testcourselog t JOIN deleted d ON t.userid = d.userid --WHERE d.statusid=4 --I think this shouldn't be required END END
THe problem is the trigger is updating 214 records and they appear to have no relation to the join.
The 3 columns below are statusid, grade and iscounted
8 NULL False 8 NULL False 7 NULL False 8 NULL False 8 NULL True 4 a True 4 a True 2 NULL True 2 NULL True 2 NULL False 8 NULL False 6 NULL True 8 NULL False 6 NULL False 8 NULL True 4 a True 8 NULL True
You can see the grade updated correctly then the trigger updated extra records. Any idea why?
Last edited by SyCo : Dec 11th, 2007 at 6:03 pm.
Hi
B.Sc Computer Science, Helwan University
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
Microsoft Student Partner
Personal blog http://ramymahrous.blogspot.com/
Arabic technical blog http://fci-h-ar.blogspot.com/
English technical blog http://fci-h.blogspot.com/
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
ajax asp database decimal seperator thousand seperator when using sql server deleting records from ms sql table where columns have duplicate values developer development hacker management studio 2005 microsoft msdn news office security software sql sql cache dependency with polling-based invalidation survey vista
- Previous Thread: Scalar Function
- Next Thread: add a new table to the database or add a new column to an existing table.


Linear Mode