Y
ygw531
Unregistered / Unconfirmed
GUEST, unregistred user!
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CountAttorneyBonus]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CountAttorneyBonus]
GO
CREATE PROCEDURE CountAttorneyBonus
@where nvarchar(1000),
@N float
-- @R int
as
begin
declare @intoducer varchar(50),@intoducername varchar(50),@N1 float,@strSql nvarchar(1000),@SqlStr nvarchar(1000),@SqlStr2 nvarchar(1000)
declare @attorneyid varchar(50),@customerid varchar(50), @customer varchar(50),@attorneyname varchar(50),@investissue varchar(20),@tablename varchar(50),@investmoney money,@investmoneySum money
declare @tmp table(customerid varchar(20),customer varchar(20),attorneyid varchar(20), attorneyname varchar(20),investissue varchar(20),investmoney money,investMoneySum money,intoducername varchar(50))
create table #temp1 (attorneyid varchar(50),attorneyname varchar(50))
create table #temp2 (customerid varchar(20),customer varchar(20),attorneyid varchar(20), attorneyname varchar(20),investissue varchar(20),investmoney money,investMoneySum money)
set @strSql='insert into #temp1 select attorneyid,attorneyname from attorneyinfo_table where '+ @where
exec sp_executesql @strSql
DECLARE Person CURSOR for
select attorneyid,attorneyname from #temp1
open person
fetch next from person
into @intoducer,@intoducername
while @@FETCH_STATUS = 0
begin
set @N1=@N/100
set @SqlStr='insert into #temp2 select customerid,customer,attorneyid,attorneyname,investissue,investmoney, sum(investmoney)*0.02 as investmoneySum from Investinfo_view where introducer= '''+ @intoducer +''' group by customerid,customer,attorneyid,attorneyname,investissue,investmoney '
exec(@SqlStr)
set @SqlStr2='select @a=customerid,@b=customer,@c=attorneyid,@d=attorneyname,@e=investissue,@f=investmoney,@g=investMoneySum from #temp2 '
exec sp_executesql @SqlStr2,N'@a varchar(20),@b varchar(20),@c varchar(20),@d varchar(20),@e varchar(20),@f money,@g money output',@customerid,@customer,@attorneyid,@attorneyname,@investissue,@investmoney,@investmoneySum output
insert into @tmp(customerid,customer,attorneyid,attorneyname,investissue,investmoney,investMoneySum,intoducername)
values (@customerid,@customer,@attorneyid,@attorneyname,@investissue,@investmoney,@investmoneySum,@intoducername)
fetch next from person
into @intoducer,@intoducername
end
close person
deallocate person
select * from @tmp
end
go
drop procedure [dbo].[CountAttorneyBonus]
GO
CREATE PROCEDURE CountAttorneyBonus
@where nvarchar(1000),
@N float
-- @R int
as
begin
declare @intoducer varchar(50),@intoducername varchar(50),@N1 float,@strSql nvarchar(1000),@SqlStr nvarchar(1000),@SqlStr2 nvarchar(1000)
declare @attorneyid varchar(50),@customerid varchar(50), @customer varchar(50),@attorneyname varchar(50),@investissue varchar(20),@tablename varchar(50),@investmoney money,@investmoneySum money
declare @tmp table(customerid varchar(20),customer varchar(20),attorneyid varchar(20), attorneyname varchar(20),investissue varchar(20),investmoney money,investMoneySum money,intoducername varchar(50))
create table #temp1 (attorneyid varchar(50),attorneyname varchar(50))
create table #temp2 (customerid varchar(20),customer varchar(20),attorneyid varchar(20), attorneyname varchar(20),investissue varchar(20),investmoney money,investMoneySum money)
set @strSql='insert into #temp1 select attorneyid,attorneyname from attorneyinfo_table where '+ @where
exec sp_executesql @strSql
DECLARE Person CURSOR for
select attorneyid,attorneyname from #temp1
open person
fetch next from person
into @intoducer,@intoducername
while @@FETCH_STATUS = 0
begin
set @N1=@N/100
set @SqlStr='insert into #temp2 select customerid,customer,attorneyid,attorneyname,investissue,investmoney, sum(investmoney)*0.02 as investmoneySum from Investinfo_view where introducer= '''+ @intoducer +''' group by customerid,customer,attorneyid,attorneyname,investissue,investmoney '
exec(@SqlStr)
set @SqlStr2='select @a=customerid,@b=customer,@c=attorneyid,@d=attorneyname,@e=investissue,@f=investmoney,@g=investMoneySum from #temp2 '
exec sp_executesql @SqlStr2,N'@a varchar(20),@b varchar(20),@c varchar(20),@d varchar(20),@e varchar(20),@f money,@g money output',@customerid,@customer,@attorneyid,@attorneyname,@investissue,@investmoney,@investmoneySum output
insert into @tmp(customerid,customer,attorneyid,attorneyname,investissue,investmoney,investMoneySum,intoducername)
values (@customerid,@customer,@attorneyid,@attorneyname,@investissue,@investmoney,@investmoneySum,@intoducername)
fetch next from person
into @intoducer,@intoducername
end
close person
deallocate person
select * from @tmp
end
go