Solved

HOW TO MODIFIE THE LAST MODIFIED ENTRY WITH A TRIGGER ?

Posted on 2009-05-20
5
504 Views
Last Modified: 2012-06-21
Hi,
I need to change the value of a column of a table  when another column has been modified.
what is the good syntax ?

Thanks !
CREATE TRIGGER [MODIF_DEVIS_COMMENTAIRE_INTERNE] ON [dbo].[DEVIS] 
FOR UPDATE
AS
IF UPDATE(COMMENTAIRE_INTERNE)
BEGIN
	UPADTE DEVIS SET COMMENTAIRE_INTERNE SET DATE_MODIFICATION = GETDATE  WHERE /*  HOW CAN I RETRIEVE THE PK OF THE UPDATED ENTRY ???    */
END

Open in new window

0
Comment
Question by:bruno_boccara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 24434395
CREATE TRIGGER [MODIF_DEVIS_COMMENTAIRE_INTERNE] ON [dbo].[DEVIS]

FOR UPDATE

AS

IF UPDATE(COMMENTAIRE_INTERNE)

BEGIN
    UPDATE  d
    SET          COMMENTAIRE_INTERNE = <The value you want to use goes here>,
          DATE_MODIFICATION = GETDATE()
    From    DEVIS d
          Inner Join Inserted i On d.<YourPrimaryKeyGoesHere> = i.<YourPrimaryKeyGoesHere>

END
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24434400
you can find the primary key from inserted or deleted tables; to be frank, i dont really prefer TRIGGERS here, you can probably writr the code to perform the update in the same procedure where you do ur update on the other columsn
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24434403
Let's try that again:

CREATE TRIGGER [MODIF_DEVIS_COMMENTAIRE_INTERNE] ON [dbo].[DEVIS]

FOR UPDATE

AS

IF UPDATED(COMMENTAIRE_INTERNE)

BEGIN
    UPDATE  d
    SET          COMMENTAIRE_INTERNE = <The value you want to use goes here>,
          DATE_MODIFICATION = GETDATE()
    From    DEVIS d
          Inner Join Inserted i On d.<YourPrimaryKeyGoesHere> = i.<YourPrimaryKeyGoesHere>

END
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24434437
It was right the first time. :(

Sorry for the multiple posts.
0
 

Author Closing Comment

by:bruno_boccara
ID: 31583620
Perfect !!!!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question