sql server中联合两个表update数据

xiaoxiao2021-02-27  119

INSERT INTO temp2 --新建一个表,表结构跟原表结构一样,并表原表中的数据插入进去,再做测试 SELECT WarehouseTaskCode, CustCode, GoodsCode, GoodsName, GoodsModel, GoodsPackNum, GoodsPieceNum, GoodsCubage, GoodsWeight, GoodsGWeight, WarehousePosition, GoodsLock, InStockDate, GoodsPrice, GoodsTotalPrice, DamageTag, InStockType, ExpectPieceNum, ExpectCubage, ExpectWeight, ExpectGWeight, NeatenID, Recorder, RecordDate, Modifier, ModifyDate, OriginalCountry, BarcodeNum, BarcodePrefix, GoodsLatchCode, GoodsProductiondate, GateWayCode, GateWayDate, GoodsStyle, BelongToWarehouse, FinanceYear, FinanceMonth, GoodsPackUnit, GoodsPieceUnit, BargainValuta, EradioCode, CIQGoodsFNum, CIQGoodsSNum, XmlCol, Reserve_One, Reserve_Two, Reserve_Three, ZeroDate, GoodsType, DamageTagLevel FROM T_wStock select COUNT(1) FROM T_wStock select COUNT(1) FROM temp2 select COUNT(1) FROM temp2 select GoodsCode,GoodsStyle ,htype from temp2 inner join temp1 on temp2.GoodsCode = dbo.temp1.num where temp2.CustCode='GD01' and dbo.temp2.GoodsStyle!=dbo.temp1.htype GROUP BY GoodsCode,GoodsStyle ,htype update T_wStock set T_wStock.GoodsStyle = temp1.htype from T_wStock,temp1 where T_wStock.GoodsCode = temp1.num and T_wStock.CustCode='GD01' SELECT * FROM dbo.T_wStock select * from T_wStock where CustCode='GD01' and GoodsCode in ( select num from temp1) select * from temp1 select GoodsCode,GoodsStyle ,htype from T_wStock inner join temp1 on T_wStock.GoodsCode = dbo.temp1.num where T_wStock.CustCode='GD01' and dbo.T_wStock.GoodsStyle!=dbo.temp1.htype GROUP BY GoodsCode,GoodsStyle ,htype SELECT GoodsCode,COUNT(1) FROM dbo.T_wStock WHERE GoodsCode IN(SELECT num FROM dbo.temp1) GROUP BY GoodsCode select num,COUNT(1) from temp1 group by num
转载请注明原文地址: https://www.6miu.com/read-17002.html

最新回复(0)