一、创建表: drop table BFBHDD.XSMB GO create table BFBHDD.XSMB( JLBH int identity, DEPTID char(10) not null, YEARMONTH int not null, BL float not null, MBXS int not null, constraint PK_XSMB PRIMARY KEY CLUSTERED (JLBH) ) with identity_gap=1 create table BFBHDD.YDMB( JLBH int identity, YEARMONTH int not null, XSMB int not null, TCJE int not null, constraint PK_YDMB PRIMARY KEY CLUSTERED (JLBH) ) with identity_gap=1 --- 二、SQL: insert into BFBHDD.YDMB(YEARMONTH,XSMB,TCJE) values(:YEARMONTH,:XSMB,:TCJE) insert into BFBHDD.XSMB(DEPTID,YEARMONTH,BL,MBXS) values('0101',:YEARMONTH,@BL,(@XSMB-@TCMB)*(@BL/100)) 三、delphi结构: 四、在商友系统中使用“自定义查询”增加查询其销售目标与当前完成率 select M.YEARMONTH,B.DEPTID,B.DEPT_NAME,cast(cast(M.BL*1.0*100/100 as decimal(10,1)) as varchar(50)) +'%' BL,M.MBXS, sum(C.XSJE) JE,cast(cast(sum(C.XSJE)*1.0*100/MBXS as decimal(10,1)) as varchar(50)) +'%' WCBL from BFBHDD.SKTXSJL L,BFBHDD.SKTXSJLC C,BFBHDD.BM B,BFBHDD.XSMB M where L.SKTNO=C.SKTNO and L.JLBH=C.JLBH and M.DEPTID=B.DEPTID and M.DEPTID=substring(C.DEPTID,1,4) and M.YEARMONTH=201202 and L.JZRQ>='2010-1-1' and L.JZRQ<='2010-12-31' group by M.YEARMONTH,B.DEPTID,B.DEPT_NAME,M.MBXS order by B.DEPTID union select M.YEARMONTH,B.DEPTID,B.DEPT_NAME,cast(cast(M.BL*1.0*100/100 as decimal(10,1)) as varchar(50)) +'%' BL,M.MBXS, sum(C.XSJE) JE,cast(cast(sum(C.XSJE)*1.0*100/MBXS as decimal(10,1)) as varchar(50)) +'%' WCBL from BFBHDD.XSJL L,BFBHDD.XSJLC C,BFBHDD.BM B,BFBHDD.XSMB M where L.SKTNO=C.SKTNO and L.JLBH=C.JLBH and M.DEPTID=B.DEPTID and M.DEPTID=substring(C.DEPTID,1,4) and M.YEARMONTH=201202 and L.JZRQ>='2010-1-1' and L.JZRQ<='2010-12-31' group by M.YEARMONTH,B.DEPTID,B.DEPT_NAME,M.MBXS order by B.DEPTID