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 8212287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:42:12+00:00 2026-06-07T10:42:12+00:00

Hello i have a SQL Table which look like this: ID BEZEICHNUNG PREIS UPDATE_DATE

  • 0

Hello i have a SQL Table which look like this:

ID      BEZEICHNUNG  PREIS        UPDATE_DATE          FLAG

1       Drake        Room         14.06.2012 16:00     0
2       Blazer       BS           12.05.2012 14:45     0

when i change a value i want to copy the row with a new id and change the flag to 1
it should look like this:

ID      BEZEICHNUNG  PREIS        UPDATE_DATE          FLAG

1       Drake        Room         11.07.2012 09:40     1
2       Blazer       BS           12.05.2012 14:45     0
3       Dune         Room         11.07.2012 09:40     0

when i change the row the update_date updates itself and set a flag to 1.
how can i create an sql statement like this.

the current trigger look like this:

ALTER TRIGGER [dbo].[UPDT_DIENSTLEISTUNG]
   ON [dbo].[DIENSTLEISTUNG]
   AFTER INSERT, UPDATE
AS
BEGIN

   SET  NOCOUNT ON;

   UPDATE DIENSTLEISTUNG
      SET UPDATE_DATE    = getdate ()
    WHERE id IN (SELECT id
                   FROM inserted);


END;

Thanks in advance for your help

  • 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-06-07T10:42:14+00:00Added an answer on June 7, 2026 at 10:42 am

    Please create this trigger first and then try to update the table

    CREATE TRIGGER [dbo].[UPDT_DIENSTLEISTUNG]
       ON [dbo].[DIENSTLEISTUNG]
       AFTER  UPDATE
    AS
    
    BEGIN
     SET  NOCOUNT ON;
    
    DECLARE @MAX_ID INT;
    SELECT @MAX_ID=MAX(ID) FROM DIENSTLEISTUNG;
    
    declare @tmp Table(ID  int,     BEZEICHNUNG varchar(20), PREIS varchar(20),
         UPDATE_DATE datetime,      FLAG bit)
    
    insert into @tmp
    select ID,BEZEICHNUNG,PREIS,UPDATE_DATE,1 [flag] from deleted;
    
    delete T from DIENSTLEISTUNG T JOIN @tmp I
    ON T.ID=I.ID
    
    INSERT INTO DIENSTLEISTUNG
    SELECT @MAX_ID+ROW_NUMBER() OVER(ORDER BY ID) [ID],BEZEICHNUNG,PREIS,GETDATE(),0 
    FROM INSERTED
    
    INSERT INTO DIENSTLEISTUNG
    select * from @tmp
    
    
     SET  NOCOUNT OFF;
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I have a string in a sql table like this hello /r/n this
Suppose I have a table like this ID Name 1 RJ 2 Hello 3
Hello SOF community: I have a table like this InvoicingActivityStartDay InvoicingActivityEndDay 27 26 27
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello I have a mysql database with in it an addresses table. This is
I have XML column in my table which can contain XML like these 2
Hello, I have the following sql table + data: CREATE TABLE IF NOT EXISTS
Hello I have this table structure: **ProductsTable** ProductID ProductName **CategoriesTable** CategoryID CategoryName **ProductCategories** ProductID
Hello guys this is a very simplified version of my table: I will like
I have a table in which the value are Table_hello date col2 2012-01-31 23:01:01

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.