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

  • SEARCH
  • Home
  • 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 7411137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:20:28+00:00 2026-05-29T06:20:28+00:00

I’ve asked the same question some days ago, but there I wanted to solve

  • 0

I’ve asked the same question some days ago, but there I wanted to solve my problem with a separate C# program. Now I want to do it in SQL directly.

That’s my problem (Sorry for linking you to another question)

My first attempts were to create this trigger:

CREATE TRIGGER myNewTrigger ON [dbo].[myTable]
FOR INSERT
AS

INSERT INTO dbo.myTargetTable
        (TIMESTAMP, VALUE_1, VALUE_2, VALUE_3, VALUE_4)
    SELECT
        DATEADD(SECOND, TIMESTAMP_S,'19700101'), VALUE, VALUE, VALUE, VALUE
        FROM inserted

GO

This would create four rows each with the same four values. But how can I put the values of each row in one row with different columns?

Thanks for any 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-05-29T06:20:28+00:00Added an answer on May 29, 2026 at 6:20 am

    This untested Select-Statement could be your solution, if there wouldn’t be a problem with the trigger.

    First problem:

    The trigger is fired after every insert on mytable.
    After the first insert for a Timestamp, there is just one value. So you need to update after the third or fourth record.
    You do the insert for the last and not for the current timestamp. That problem is not solved in my solution.

    Second problem:

    You need to make shure, that you insert only once and not after every single row.
    You could add a NOT IN-Clause to the select statement for the insert.
    That problem isn’t solved in my solution.

    SELECT 
    DISTINCT
    TS
    ,(SELECT VALUE FROM
        (SELECT MT.TS, MT.VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable MT
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 1) AS VALUE1
    ,(SELECT VALUE FROM
        (SELECT TS, VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 2) AS VALUE2
    ,(SELECT VALUE FROM
        (SELECT TS, VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 3) AS VALUE3
    ,(SELECT VALUE FROM
        (SELECT TS, VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 4) AS VALUE4
    FROM inserted
    GROUP BY TS 
    

    Possibel Solution to your Problem, stated in the comment:

    With this untested Query, you insert the last, not the current TS into the target-table. That way you make shure you just update, when the last entry of the TS is written, so you have all of the values(1..4) written, before inserting them.

    It might be slow :-). But I don’t know a better way.

    SELECT 
     DISTINCT TOP 1
     TS
     ,(SELECT VALUE FROM
        (SELECT MT.TS, MT.VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable MT
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 1) AS VALUE1
    ,(SELECT VALUE FROM
        (SELECT TS, VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 2) AS VALUE2
    ,(SELECT VALUE FROM
        (SELECT TS, VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 3) AS VALUE3
    ,(SELECT VALUE FROM
        (SELECT TS, VALUE ,ROW_NUMBER () OVER (ORDER BY TS, VALUE) AS ROWNUMBER
        FROM myTable
        WHERE MT.TS = TS) DATASET
        WHERE DATASET.ROWNUMBER = 4) AS VALUE4
     FROM myTable
     WHERE TS < (SELECT MIN(TS) FROM INSERTED)
     AND TS NOT IN (SELECT TS FROM MyTargetTable)
     GROUP BY TS 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.