*/ DECLARE @cfbh VARCHAR(20),@yrzyls VARCHAR(20),@rq DATETIME,@zyls VARCHAR(20) SELECT @rq=GETDATE() SELECT @cfbh=CONVERT(VARCHAR(20),@rq,102),@yrzyls='',@zyls='ABC' UPDATE t2 SET t2.by1 = @cfbh+cast(t3.rowid as varchar(10)) FROM zy_brcfmx_ys t2, ( SELECT ksbh, ysbh, hlks, hlr, ssid, bcbh, yryz, youhui, ROW_NUMBER() OVER (ORDER BY ksbh, ysbh, hlks, hlr, ssid, bcbh, yryz, youhui ASC) AS ROWID FROM ( SELECT t2.ksbh,t2.ysbh,t2.hlks,t2.hlr,t2.ssid,t2.bcbh,t2.yryz,t2.youhui FROM zybrzl t1,zy_brcfmx_ys t2 WHERE t1.zyls = t2.zyls AND t2.shbz = 1 AND t2.zhscrq = @rq AND t1.zyls = @zyls AND isnull(t2.yryz,'') = @yrzyls GROUP BY t1.blh,t1.xm,t1.ickh,t1.nl,t1.nldw,t1.sflx,t1.xb, t2.ksbh,t2.ysbh,t2.hlks,t2.hlr,t2.ssid,t2.bcbh,t2.yryz,t2.youhui UNION SELECT t2.ksbh,t2.ysbh,t2.hlks,t2.hlr,t2.ssid,t2.bcbh,t2.yryz,t2.youhui FROM zybrzl t1,zy_brcfmx_ys_fjxm t2 WHERE t1.zyls = t2.zyls AND t2.shbz = 1 AND t2.zhscrq = @rq AND t1.zyls = @zyls AND isnull(t2.yryz,'') = @yrzyls GROUP BY t1.blh,t1.xm,t1.ickh,t1.nl,t1.nldw,t1.sflx,t1.xb, t2.ksbh,t2.ysbh,t2.hlks,t2.hlr,t2.ssid,t2.bcbh,t2.yryz,t2.youhui ) t ) t3 WHERE t2.ksbh = t3.ksbh AND t2.ysbh = t3.ysbh AND t2.youhui = t3.youhui AND isnull(t2.hlks,'') = isnull(t3.hlks,'') AND isnull(t2.hlr,'') = isnull(t3.hlr,'') AND isnull(t2.ssid,'') = isnull(t3.ssid,'') AND isnull(t2.yryz,'') = isnull(t3.yryz,'') AND isnull(t2.bcbh,'') = isnull(t3.bcbh,'') AND t2.shbz = 1 AND t2.zhscrq = @rq AND t2.zyls = @zyls and t2.cflx=10 AND isnull(t2.yryz,'') = @yrzyls
SELECT t2.ksbh,t2.ysbh,t2.hlks,t2.hlr,t2.ssid,t2.bcbh,t2.yryz,t2.youhui
FROM zybrzl t1,zy_brcfmx_ys t2
WHERE t1.zyls = t2.zyls AND t2.shbz = 1 AND t2.zhscrq = @rq AND t1.zyls = @zyls AND isnull(t2.yryz,'') = @yrzyls
GROUP BY t1.blh,t1.xm,t1.ickh,t1.nl,t1.nldw,t1.sflx,t1.xb,t2.ksbh,t2.ysbh,t2.hlks,t2.hlr,t2.ssid,t2.bcbh,t2.yryz,t2.youhui
------解决方案-------------------- 你还不如多加几个临时表,用临时表去更新。
------解决方案-------------------- 用临时表处理比较好,如果不是实时的数据更新的话,还是比较一个比较好的选择。
------解决方案--------------------