ALTER PROCEDURE [dbo].[gup_p_filtermoney]
AS
BEGIN
CREATE TABLE #temp1(
[code] [varchar](10) NOT NULL,
[name] [varchar](50) NULL,
[run_time] [datetime] NOT NULL,
[amounts] [decimal](18, 5) NULL,
[counts] [int] NULL,
)
declare @day_count int ,@daysuc_count int
declare @days int
declare @run_time datetime
set @days=15
set @run_time=GETDATE()
select @day_count= count(update_time) from
(select distinct update_time
from dde_fund_flow
where DATEPART(hour,update_time) =16
and DateDiff(dd,update_time,getdate())<=@days ) a
set @daysuc_count=@day_count/2 +2
Insert into #temp1 (code,name,run_time,amounts,counts)
select a.share_code AS code,a.name ,convert(varchar(23),@run_time,120) as run_time ,a.amounts,b.counts from
(select share_code,name ,SUM (net_amount) as amounts
from dde_fund_flow , shares
where dde_fund_flow.share_code =shares.code
and DateDiff(dd,update_time,getdate())<=15
and DATEPART(hour,update_time) =16
group by share_code,name
having SUM (net_amount)>0 ) a ,
(select share_code, count (net_amount) as counts from dde_fund_flow
where DateDiff(dd,update_time,getdate())<=15
and net_amount >0 and DATEPART(hour,update_time) =16
group by share_code
having count (net_amount) >1 ) b
where a.share_code=b.share_code
and b.counts>@daysuc_count
order by counts desc ,a.amounts desc
select * from #temp1
end