Selecting 10 rows from parent SQL table and Pasting it in a new SQL table

Anonymous
2023-09-09T04:48:20.2866667+00:00

Hi, My Query is -

I have 2 SQL tables employee01 and employee02

employee01 has 100 rows. employee02 has 0 row.

employee01 - Screenshot 2023-09-09 201052

What I want is - 10 unique rows to be copied from employee01 to employee02 in every 1 hour duration.

I want to know the Stored Procedure SQL query only.

I've done the Logic App for the Recurrence (every 1 hr copying part)

CREATE PROCEDURE [dbo].[GetEmployee]
AS
BEGIN
 INSERT INTO employee02
 SELECT TOP(10)FirstName, LastName
 FROM employee01
END

-- Problem with My SQL query is that --

  1. It is selecting same top 10 data after every one hour. Which is not unique
Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 120K Reputation points MVP
    2023-09-09T19:27:23.12+00:00

    You would add WHERE NOT EXISTS to filter out rows you have already added.

    As this appears to be some sort of assignment, I am only giving you a hint, now the full solution, but leave it to you to explore on your own. You learn better that way.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.