SQL-一次执行两个更新查询

SQL-一次执行两个更新查询,sql,sql-server-2008,sql-update,Sql,Sql Server 2008,Sql Update,我试图使用更新脚本将一个表中的值分配到另一个表中 对于一个具有匹配可能性的记录,这很好 UPDATE Template_Survey SET K2ref = tbAsset.AssetNo FROM Template_Structure_Location INNER JOIN Template_Survey ON Template_Structure_Loca

我试图使用更新脚本将一个表中的值分配到另一个表中

对于一个具有匹配可能性的记录,这很好

UPDATE    Template_Survey
SET              K2ref = tbAsset.AssetNo
FROM         Template_Structure_Location INNER JOIN
                      Template_Survey ON 
                      Template_Structure_Location.TEMPLATE_STRUCTURE_LOCATION_REF = Template_Survey.TEMPLATE_STRUCTURE_LOCATION_REF INNER JOIN
                      tbAsset ON Template_Structure_Location.RoomID = tbAsset.LocationID AND Template_Structure_Location.RoomID = tbAsset.LocationID
WHERE     K2transferNote ='Reallocate - same no of spare items' and (tbAsset.AssetName = 'Archive or re-use') and (TEMPLATE_SURVEY_REF = 4369 or TEMPLATE_SURVEY_REF = 4405)
and (Template_Survey.K2ref = 0 OR
                      Template_Survey.K2ref IS NULL)
但是,如果Template_调查表和tbAsset表中有两条记录符合条件,则tbAsset表中找到的第一条记录将用作Template_调查表中两条记录的值

当只有一个可能的记录时,我运行第二个查询来更新tbAsset.AssetName值,以便上一个查询无法再找到该记录

UPDATE tbAsset
SET tbAsset.AssetName = 'Reallocated to item in same location-needs update'
WHERE     (AssetNo IN
                      (SELECT     K2Ref
                        FROM         Template_Survey)) and  (tbAsset.AssetName = 'Archive or re-use')
在重复该过程之前,我如何编写一些东西来执行第一次查询一条记录,然后执行第二次查询相应记录,以便每次都能找到一条不同的记录


提前谢谢。抱歉,如果没有多大意义,那么很难解释。

如果是多行,那么每行的tbAsset.assetn是否都不相同?对于响应延迟,我深表歉意。tbAsset.AssetNo在tbAsset表中是唯一的,但在模板\u调查结果中返回的结果是重复的。