0

I need to update a second table with the results of this query:

SELECT Tag, battery, Wearlevel, SensorTime 
FROM ( 
SELECT m.* , ROW_NUMBER() OVER (PARTITION BY TAG ORDER BY SensorTime DESC) AS rn 
FROM [dbo].[TELE] m  
) m2 
where m2.rn = 1; 

But. I had a hard time fixing the SET without messing it up. I want to have a table which has all data from last date of each TAG without duplicates.

Pastagolf
  • 3
  • 1

1 Answers1

0

Below code maybe you want.

enter image description here

UPDATE
    Table_A
SET
    Table_A.Primarykey = 'ss'+Table_B.Primarykey,
    Table_A.AddTime = 'jason_'+Table_B.AddTime
FROM
    Test AS Table_A
    INNER JOIN UsersInfo AS Table_B
        ON Table_A.id = Table_B.id
WHERE
    Table_A.Primarykey = '559713e6-0d85-4fe7-87a4-e9ceb22abdcf'

For more details, you also can refer below posts and blogs.

1. How do I UPDATE from a SELECT in SQL Server?

2. How to UPDATE from SELECT in SQL Server

Jason Pan
  • 15,263
  • 1
  • 14
  • 29