一开始以为要用游标,但没想到网上有高人指点,代码如下:
update yc.dbo.T_CUST_CUSTINFO_12 set yc.dbo.T_CUST_CUSTINFO_12.a611=n.a611, yc.dbo.T_CUST_CUSTINFO_12.a612=n.a612, yc.dbo.T_CUST_CUSTINFO_12.a613=n.a613, yc.dbo.T_CUST_CUSTINFO_12.a614=n.a614, yc.dbo.T_CUST_CUSTINFO_12.a615=n.a615, yc.dbo.T_CUST_CUSTINFO_12.a616=n.a616, yc.dbo.T_CUST_CUSTINFO_12.a617=n.a617, yc.dbo.T_CUST_CUSTINFO_12.a618=n.a618, yc.dbo.T_CUST_CUSTINFO_12.a622=n.a622, yc.dbo.T_CUST_CUSTINFO_12.a623=n.a623, yc.dbo.T_CUST_CUSTINFO_12.a624=n.a624, yc.dbo.T_CUST_CUSTINFO_12.a625=n.a625, yc.dbo.T_CUST_CUSTINFO_12.a626=n.a626, yc.dbo.T_CUST_CUSTINFO_12.a629=n.a629, yc.dbo.T_CUST_CUSTINFO_12.a630=n.a630, yc.dbo.T_CUST_CUSTINFO_12.a631=n.a631 from yc.dbo.T_CUST_CUSTINFO_12 o left join T_CUST_CUSTINFO_12 n on o.id=n.id
REF URL:http://www.360doc.com/content/08/1118/16/16915_1951567.shtml#
-----------------------------------------------------------------------------------------------
ps:不仅是2表,多表也可以,请看下面的例子:
select * into #t from temp_easypart where AD_CusI_cgshbm='GBB00122' and IsDealed = 1 update [Ad_CustomerIntegral] --(18575 行受影响) set AD_CusI_hdjf =round(#t.AD_CusI_dgsl*convert(numeric(18,2),r.AD_CIR_bjfbl),0,0) from #t inner join Customer c on #t.AD_CusI_cgshbm collate SQL_Latin1_General_CP1_CI_AS = c.Username inner join AD_BoshProductInfo p on #t.AD_CusI_cpbm = p.AD_boProI_cpbh inner join AD_cIntegralrule r on p.AD_boProI_zdbh = r.AD_CIR_bcpbh and r.AD_CIR_bjxslx = c.Delertype_id inner join Ad_CustomerIntegral i on i.AD_CusI_cgshbm collate SQL_Latin1_General_CP1_CI_AS = c.Username and i.AD_CusI_cpbm collate SQL_Latin1_General_CP1_CI_AS = p.AD_boProI_cpbh and i.AD_CusI_ddbh = #t.AD_CusI_ddbh collate SQL_Latin1_General_CP1_CI_AS