sql server从另一张表读点数据更新的一张表里的SQL,
以前不知道怎么写,有游标,现在知道了,比较好用
update A set _SUM_PASSTIME = B.a1,
_SUM_WORK = B.a2,
_COUNT_END= B.a3,
_SUM_TAX =B.a4
FROM #TG_OO1 A,
(select TE_PASS_RANGE, SUM(TE_PASS_TIME_HOUR) a1,SUM(TE_OPERATE_TIME) a2,COUNT(*) a3,SUM(TE_RATEPAY_HOUR) a4 FROM TG_ENTRY WHERE TE_NOT_IN_FLAG = 0 and TE_ENDPASS_FLAG = 1 group by TE_PASS_RANGE) B
where A.TE_PASS_RANGE = B.TE_PASS_RANGE COLLATE CHINESE_PRC_CS_AS_WS;
_SUM_WORK = B.a2,
_COUNT_END= B.a3,
_SUM_TAX =B.a4
FROM #TG_OO1 A,
(select TE_PASS_RANGE, SUM(TE_PASS_TIME_HOUR) a1,SUM(TE_OPERATE_TIME) a2,COUNT(*) a3,SUM(TE_RATEPAY_HOUR) a4 FROM TG_ENTRY WHERE TE_NOT_IN_FLAG = 0 and TE_ENDPASS_FLAG = 1 group by TE_PASS_RANGE) B
where A.TE_PASS_RANGE = B.TE_PASS_RANGE COLLATE CHINESE_PRC_CS_AS_WS;