Stored procedures 使用datetime将列从一个联接更新为多个联接

Stored procedures 使用datetime将列从一个联接更新为多个联接,stored-procedures,sql-update,row,partitioning,Stored Procedures,Sql Update,Row,Partitioning,我需要通过parent1cellphone或parent2cellphone在花名册表中查找值来更新qrscaninfo表中的ruid列。 我只是不知道如何编写连接以使用qrscaninfo表中创建的第一个日期更新行 这是qrscaninfotable Id UserPhoneNumber Created RUID 153 6785555555 8/25/20 19:19 NULL 153 6785555555 8/25/20 19:19

我需要通过parent1cellphoneparent2cellphone在花名册表中查找值来更新qrscaninfo表中的ruid列。 我只是不知道如何编写连接以使用qrscaninfo表中创建的第一个日期更新行

这是qrscaninfotable

Id  UserPhoneNumber  Created          RUID
153 6785555555       8/25/20 19:19    NULL
153 6785555555       8/25/20 19:19    NULL
164 6785555555       8/26/20 17:24    NULL
这是登记表

UID       School              Parent1CellPhone    Parent2CellPhone   Week 1
8498665   Love Development    6785555555          6785555556         NULL
这是Site2表

SITE                  Week 1
Love Development      8/25/20 0:00
结果应该是什么

Id    UserPhoneNumber   Created          RUID
153   6785555555        8/25/20 19:19    8498665
153   6785555555        8/25/20 19:19    NULL
164   6785555555        8/26/20 17:24    NULL
我到目前为止有什么疑问

Update qr
set ruid = pr.UID
from dbo.QRScanInfo as qr
inner join  [dbo].[Rosters] as pr
    on pr.Parent1cellphone = qr.UserPhoneNumber
left join dbo.Sites2 as s2 
    on s2.site = pr.school
inner join dbo.qrscaninfo qr2
    on cast (s2.[Week 1] as date) = cast (qr2.created as date)
where pr.UID = '8498665'