Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:23:40+00:00 2026-05-27T13:23:40+00:00

I have an update trigger, part of which is below that is causing the

  • 0

I have an update trigger, part of which is below that is causing the problem.

if ( (select [Account] from inserted) != (select [Account] from deleted))
    begin
    UPDATE Customers SET active_changed = CONVERT(varchar(10),GetDate(),102)
    FROM Customers ,INSERTED
    WHERE Customers .ID = INSERTED.ID
    end

If I do query like this

UPDATE Customers SET RepID= '111'  where repID = '222'

this does not work because the clause in the Update trigger fetches multiple records and it can not be executed.But if I do this

UPDATE Customers SET RepID = '111' where ID = '12345'    

It works because ID is unique and fetches only one record.

Does someone has a remedy for this and a better way to rewrite my trigger?

What I am doing in the trigger is, if a a particular field in the record [Active] is changed (example: record made active or inactive), I am recording that date and put it in one of the field [active_changed]. This is just for audit purpose.

Apologies, I explained a bit wrong before, now fixed.

Any advice

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:23:41+00:00Added an answer on May 27, 2026 at 1:23 pm

    Based on the requirement “I would like to register the date at which, it was changed. Account can either be ‘active’ or ‘not-active’.” I think you want this :

    UPDATE Customers 
       SET active_changed = CONVERT(varchar(10),GetDate(),102)
      FROM Customers upd
      JOIN inserted i -- match by ID with new version
        ON i.ID = upd.ID
      JOIN deleted d -- match by ID with old version 
        ON d.ID = upd.ID
     WHERE i.Account <> d.Account -- when changed
    

    This assumes the records ‘never’ get updated on the ID field. If you also want to catch the situation where an UPDATE can do that and you want such an operation also to set the active_changed field, you’ll need something like below :

    UPDATE Customers 
       SET active_changed = CONVERT(varchar(10),GetDate(),102)
      FROM Customers upd
      JOIN inserted i -- match by ID with new version
        ON i.ID = upd.ID
      LEFT OUTER JOIN deleted d -- match by ID with old version (might not have existed yet
                   ON d.ID = upd.ID
     WHERE i.Account <> d.Account -- when changed
        OR d.ID IS NULL -- or when coming from different ID
    

    Hope this helps.

    PS: Why store the active_changed as a varchar instead of a datetime ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to use an update trigger which checks for the title_id
I've been trying to solve a slow trigger problem and now that I have
I have a trigger that executes a function on table insert or update. It
If I have a trigger before the update on a table, how can I
I have a search button tied to an update panel as a trigger like
I have a table where on a single record update, a trigger adds a
We have created a table with a trigger that updates a ModifiedDate field in
I have an auditing trigger that automatically places the time something was updated and
I have update panel that content check box, textbox, 3 DropDownList with CascadingDropDown extender.
I have an UPDATE sql command that modifies a Date/Time field in a particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.