## 新人开发，求提供思路

3000条记录每一条计算1秒。3000条就是3000秒。

a3是最后要的【扣款单价】，且a3=a1+a2

a1来自表【B】【C】【D】经过各种判断而来

a2来自表【E】【F】经过各种判断而来

ALTER PROCEDURE [dbo].[sp_kkCalculateJggj]

@jggx nvarchar(50),
@cpmc nvarchar(50),
@lskbh nvarchar(50),
@nfbh nvarchar(50),
@value decimal(18,3) output

AS
declare
@i int, --循环变量
@jgdj decimal(18,3),
@jggj decimal(18,3),
@Finterid int,
@Fentryid int

set @jgdj=0
set @jggj=0
set @i=1
select top 1 @Fentryid=Fentryid,@Finterid=Finterid from gspscb.dbo.cp_gxdj
where cpmc=@cpmc and jggx=@jggx

WHILE @i<=@Fentryid
BEGIN
select @jggx=jggx  from gspscb.dbo.cp_gxdj
where Finterid=@Finterid and Fentryid=@i and cpmc=@cpmc
--获得单个工序单价
exec [sp_kkCalculateJgdj_new] @jggx,@cpmc,@lskbh,@nfbh,@jgdj output
set @jggj=@jggj+@jgdj
set @i=@i+1
END

set @value=@jggj

ALTER PROCEDURE [dbo].[sp_kkCalculateJgdj_new]
@jggx nvarchar(50),
@cpmc nvarchar(50),
@lskbh nvarchar(50),
@nfbh nvarchar(50),
@jgdj decimal(18,3) output --输出jgdj
AS
declare
@id int,
@devicename nvarchar(50),
@vtx nvarchar(50),
@ftx nvarchar(50),
@ballsize nvarchar(50),
@ftype nvarchar(50),
@rclcd decimal(18,3),
@jgdw nvarchar(20)

--如果有淬火工序
if(charindex('淬火',@jggx) > 0)
begin
select top(1) @ftype=ftype,@rclcd=rclcd from gspscb.dbo.s_cprclcd where cpmc=@cpmc and jggx= @jggx
select top(1)@jgdj=rcldj FROM gspscb.dbo.s_rcldj where ftype=@ftype and @rclcd between fminlength and fmaxlength order by Fsdate desc
end
else
begin
--搜索流水卡信息
SELECT top 1 @id=t1.worktaskid,@devicename=isnull(t1.devicename,''),@vtx=isnull(t1.vtx,''),@ftx=isnull(t1.ftx,''),@ballsize=isnull(t1.ballsize,'') FROM task.dbo.t_worktask t1 LEFT OUTER JOIN task.dbo.t_order t2 ON t1.produceplanno = t2.orderid WHERE t2.wastecardno=@lskbh and t2.year=@nfbh and t1.workprocedurename=@jggx
--如果有流水卡编号
if(@id is not null)
begin
select top 1 @jgdj=unitprice from task.dbo.t_workprice where workprocedurename=@jggx and isnull(devicename,'')=@devicename and isnull(vtx,'')=@vtx and isnull(ftx,'')=@ftx and isnull(ballsize,'')=@ballsize order by begindate desc
end
--如果没有流水卡编号
else
begin
select @jgdj=max(unitprice) from task.dbo.t_workprice where workprocedurename=@jggx
end
end
if(@jgdj is null)
begin
select top(1) @jgdj=jgdj,@jgdw=jgdw from gspscb.dbo.S_CPGXDJK_wx where jggx=@jggx and cpmc =@cpmc order by fsdate desc
if(@jgdw='热处理部')
begin
set @rclcd=@jgdj
set @jgdj=null
select top(1) @ftype=ftype from gspscb.dbo.s_cprclcd where cpmc=@cpmc
select top(1)@jgdj=rcldj FROM gspscb.dbo.s_rcldj where ftype=@ftype and @rclcd between fminlength and fmaxlength order by Fsdate desc
end
end
if(@jgdj is null)
begin
set @jgdj=0
insert into koukuan.dbo.no_jgdj select @cpmc,@jggx,@lskbh,@nfbh
end

0

a1来自表【B】【C】【D】经过各种判断而来
a2来自表【E】【F】经过各种判断而来
-----------------------------------------------------------------------------------------------

0

0