update xs1 set 运销类型 = 1 where 运销类型 = '调运'
update xs1 set 运销类型 = 0 where 运销类型 = '销售'
insert into cars(chepai,chexing,yanse,pizhong,zaizhong,chezhu,dianhua,leixing)
select 车牌号,车型,颜色,皮重,载重,车主名称,车主联系方式,运销类型 from xs1;
update cars set jihuo = 1,contractNum = 0,selected = 0,del = 0,remark = '';
/*更新皮重*/
use work;
update cars set cars.pizhong = (select deadweight from truckimf where cars.chepai = truckimf.id)
where exists(select * from truckimf where cars.chepai = truckimf.id);
update cars set cars.pizhong = (select top 1 deadweight from truckimf where cars.chepai = truckimf.drivername)
where exists(select * from truckimf where cars.chepai = truckimf.drivername);
select count(*) from truckimf,cars where cars.chepai = truckimf.drivername group by drivername;
select cars.chepai,cars.pizhong,truckimf.deadweight,truckimf.id from cars,truckimf where cars.chepai = truckimf.id;
/*消除重复键*/
1、建立一张临时的车辆皮表
CREATE TABLE [TRUCKIMF2] (
[ID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[DriverName] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
[deadweight] [decimal](10, 2) NULL ,
[unit] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
[mode] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
[innerid] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
[b_send] [bit] NULL
) ON [PRIMARY]
GO
2、建立索引,忽略重复键
3、插入数据
insert into truckImf2(id,deadweight,unit)
select id,deadweight,unit from truckImf where len(id) > 3;
insert into truckImf2(id,deadweight,unit)
select drivername,deadweight,unit from truckImf where len(id) < 4;
4、更新cars表的数据
update cars set cars.pizhong = (select deadweight from truckimf2 where cars.chepai = truckimf2.id)
where exists(select * from truckimf2 where cars.chepai = truckimf2.id);
update cars set cars.chedui = (select unit from truckimf2 where cars.chepai = truckimf2.id)
where exists(select * from truckimf2 where cars.chepai = truckimf2.id);
alter table cars add chedui varchar(20) null;
update cars set chedui = '销售' where leixing = 0;