create proc proc_ywytc<br><br> @proid varchar(50)<br>as<br><br> /*<br><br> exec proc_ywytc<br><br> create proc proc_ywytc<br> @proid varchar(50)<br> as<br><br> SELECT * from V_skhz_ywy where proid='20080100'<br> <br> SELECT * from ywytc<br><br> */<br> declare @ywy varchar(50)<br> declare @zwf varchar(50)<br> declare @hwf varchar(50)<br> declare @ggf varchar(50)<br> declare @cdggf varchar(50)<br> declare @xcggf varchar(50)<br> declare @qtfy varchar(50)<br><br> declare @qsje decimal(18,2)<br> declare @zzje decimal(18,2)<br><br> declare @tcbl decimal(18,2)<br> declare @tc decimal(18,2)<br> declare @tce decimal(18,2)<br> declare @tcs decimal(18,2)<br> declare @tcsi decimal(18,2)<br> declare @tcw decimal(18,2)<br> declare @tcl decimal(18,2)<br><br> declare @ibcount int<br> declare @iecount int<br><br> --创建临时表 两个字段<br> create table #ywytc <br> (业务人员 varchar(10),展位费 decimal(18,2),提成一 decimal(18,2),会务费 decimal(18,2),提成二 decimal(18,2), 会刊广告费 decimal(18,2),提成三 decimal(18,2), 场地广告费 decimal(18,2),提成四 decimal(18,2),宣传广告费 decimal(18,2),提成五 decimal(18,2),其他费用 decimal(18,2),提成六 decimal(18,2),总提成额 decimal(18,2))<br> <br> declare ff cursor for SELECT ywy,zwf,hwf,ggf,cdggf,xcggf,qtfy from V_skhz_ywy where proid=@proid<br><br> set @ibcount=0<br> select @iecount=count(*) from V_skhz_ywy where proid=@proid<br> open ff<br> while @ibcount<=@iecount-1<br> begin<br> fetch next from ff<br> into @ywy,@zwf,@hwf,@ggf,@cdggf,@xcggf,@qtfy<br><br> /* <br> SELECT * from ywytc where 费用类型编号='zwf'<br> SELECT * from ywytc where 费用类型编号='hwf'<br> SELECT * from ywytc where 费用类型编号='ggf'<br> SELECT * from ywytc where 费用类型编号='cdggf'<br> SELECT * from ywytc where 费用类型编号='xcggf'<br> SELECT * from ywytc where 费用类型编号='qtfy'<br> */<br> declare tc cursor for SELECT 起始金额,终止金额,提成比例 from ywytc where 展会项目编号=@proid and 费用类型编号='zwf'<br> open tc<br> fetch next from tc into @qsje,@zzje,@tcbl<br> while @@FETCH_STATUS = 0<br> begin<br> if @zwf>=@qsje and @zwf<=@zzje<br> set @tc=@zwf*@tcbl/100 <br> fetch next from tc into @qsje,@zzje,@tcbl <br> end<br> close tc<br> deallocate tc<br><br> declare tc cursor for SELECT 起始金额,终止金额,提成比例 from ywytc where 展会项目编号=@proid and 费用类型编号='hwf'<br> open tc<br> fetch next from tc into @qsje,@zzje,@tcbl<br> while @@FETCH_STATUS = 0<br> begin<br> if @hwf>=@qsje and @hwf<=@zzje<br> set @tce=@hwf*@tcbl/100 <br> fetch next from tc into @qsje,@zzje,@tcbl <br> end<br> close tc<br> deallocate tc<br><br> declare tc cursor for SELECT 起始金额,终止金额,提成比例 from ywytc where 展会项目编号=@proid and 费用类型编号='ggf'<br> open tc<br> fetch next from tc into @qsje,@zzje,@tcbl<br> while @@FETCH_STATUS = 0<br> begin<br> if @ggf>=@qsje and @ggf<=@zzje<br> set @tcs=@ggf*@tcbl/100 <br> fetch next from tc into @qsje,@zzje,@tcbl <br> end<br> close tc<br> deallocate tc<br><br> declare tc cursor for SELECT 起始金额,终止金额,提成比例 from ywytc where 展会项目编号=@proid and 费用类型编号='cdggf'<br> open tc<br> fetch next from tc into @qsje,@zzje,@tcbl<br> while @@FETCH_STATUS = 0<br> begin<br> if @cdggf>=@qsje and @cdggf<=@zzje<br> set @tcsi=@cdggf*@tcbl/100 <br> fetch next from tc into @qsje,@zzje,@tcbl <br> end<br> close tc<br> deallocate tc<br><br> declare tc cursor for SELECT 起始金额,终止金额,提成比例 from ywytc where 展会项目编号=@proid and 费用类型编号='xcggf'<br> open tc<br> fetch next from tc into @qsje,@zzje,@tcbl<br> while @@FETCH_STATUS = 0<br> begin<br> if @xcggf>=@qsje and @xcggf<=@zzje<br> set @tcw=@xcggf*@tcbl/100 <br> fetch next from tc into @qsje,@zzje,@tcbl <br> end<br> close tc<br> deallocate tc<br><br> <br><br> declare tc cursor for SELECT 起始金额,终止金额,提成比例 from ywytc where 展会项目编号=@proid and 费用类型编号='qtfy'<br> open tc<br> fetch next from tc into @qsje,@zzje,@tcbl<br> while @@FETCH_STATUS = 0<br> begin<br> if @qtfy>=@qsje and @qtfy<=@zzje<br> set @tcl=@qtfy*@tcbl/100 <br> fetch next from tc into @qsje,@zzje,@tcbl <br> end<br> close tc<br> deallocate tc<br><br><br> insert #ywytc <br> select @ywy,@zwf,@tc,@hwf,@tce,@ggf,@tcs,@cdggf,@tcsi,@xcggf,@tcw,@qtfy,@tcl,@tc+@tce+@tcs+@tcsi+@tcw+@tcl<br> --select @ywy 业务人员,@zwf 展位费,@tc 提成,@hwf 会务费,@tce 提成,@ggf 会刊广告费,@tcs 提成,@cdggf 场地广告费,@tcsi 提成,@xcggf 宣传广告费,@tcw 提成,@qtfy 其他费用,@tcl 提成,@tc+@tce+@tcs+@tcsi+@tcw+@tcl 总提成额<br><br> set @ibcount=@ibcount+1<br> end<br> close ff<br> deallocate ff<br><br> select * from #ywytc<br> <br> /*<br><br> DECLARE @RC int<br>DECLARE @proid varchar(50)<br>SELECT @proid = '20080100'<br>EXEC @RC = [dbo].[proc_ywytc] @proid<br>DECLARE @PrnLine nvarchar(4000)<br>PRINT '存储过程: dbo.proc_ywytc'<br>SELECT @PrnLine = ' 返回代码 = ' + CONVERT(nvarchar, @RC)<br>PRINT @PrnLine<br><br> */<br><br>GO<br><br><br>@proid 是项目编号<br>我写了一个存储过程,完成了,大家看看还有没有更好的办法。