更新查询出的多条记录


①查询出下图的语句:

SELECT * FROM 
(SELECT GUID, GModel,ExpQty,ReqmtNo,ExpNo FROM House_Exp_List WHERE ExpNo = '8b3973af-0302-4b45-8e8c-00787c9ce58b') A
RIGHT JOIN 
(
	  SELECT GModel GModel1,ExpQty ExpQty1,max(ReqmtNo) ReqmtNo1 FROM House_Exp_List WHERE ExpNo = '21d7e092-5ab1-4166-9c60-059e07ac7537'
	 GROUP BY GModel,ExpQty
) B
ON A.ExpQty = B.ExpQty1 AND A.GModel = B.GModel1


更新查询出的多条记录_第1张图片


②更新语句:

UPDATE A SET A.ReqmtNo=B.ReqmtNo1
FROM
 (
	SELECT GUID, GModel,ExpQty,ReqmtNo,ExpNo FROM House_Exp_List WHERE ExpNo = '8b3973af-0302-4b45-8e8c-00787c9ce58b'
 ) A
RIGHT JOIN 
(
	 SELECT GModel GModel1,ExpQty ExpQty1,max(ReqmtNo) ReqmtNo1 FROM House_Exp_List WHERE ExpNo = '21d7e092-5ab1-4166-9c60-059e07ac7537'
	 GROUP BY GModel,ExpQty
) B
ON A.ExpQty = B.ExpQty1 AND A.GModel = B.GModel1
WHERE ExpNo = '8b3973af-0302-4b45-8e8c-00787c9ce58b'




③更新后的结果(用①的语句再次查询):




完美收官。





你可能感兴趣的:(更新查询出的多条记录)