Hi @VDT-7677 ,
For this type of problem we recommend that you post CREATE TABLE statements for your tables together with INSERT statements with sample data, enough to illustrate all angles of the problem. We also need to see the expected result of the sample.
You could try with below which has the least modification based on your code.
UPDATE [T1]
SET
[T1].[First_Name] = [S1].[First_Name],
[T1].[Last_Name] = [S1].[Last_Name]
FROM [dbo].[Test] [T1]
CROSS APPLY
(
SELECT top 1 [First_Name],[Last_Name]
FROM
[dbo].[Sample]
--TABLESAMPLE (1000 ROWS) --add this line if necessary
WHERE
[T1].[Row_ID] = [T1].[Row_ID]
ORDER BY NEWID(),[T1].[Row_ID]
) [S1]
In additon, you could also try with Rank() function which is similar with RowNumber() function mentioned by Erland as below:
; WITH T1_numbering AS (
SELECT First_Name, Last_Name, RANK() OVER(ORDER BY Row_ID) AS RANKID
FROM test
), S_Numbering AS (
SELECT First_Name, Last_Name, RANK() OVER(ORDER BY newid()) AS RANKID
FROM Sample
)
UPDATE T1
SET First_Name = S.First_Name,
Last_Name = S.Last_Name
FROM T1_Numbering T1
JOIN S_Numbering S ON T1.RANKID = S.RANKID
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues October--Users always get connection timeout problem when using multi subnet AG via listener. Especially after failover to another subnet