내가 작성한 스토리지 프로세스

39725 단어 저장 프로세스
--    :    10      
---2011-11-11    lp,          
IF exists (select * from SysObjects where name='sp_reportlist' and type='p')
   drop procedure sp_reportlist
go
 
CREATE PROCEDURE sp_reportlist
@stockcode nvarchar(20)
as
if(@stockcode!='')
begin
 
SELECT top 10 T1.ReportID,T1.StockCode,T2.ReportTitle,T3.SourceID,T3.CompanyName,T3.CompanyShortName,  
CASE  
WHEN T1.Grade=0 THEN '   ' WHEN T1.Grade=1 THEN '  '  WHEN T1.Grade=2 THEN '  ' WHEN T1.Grade=3 THEN '  '  
WHEN T1.Grade=4 THEN '  ' WHEN T1.Grade=5 THEN '  ' END AS Grade, 
 CASE 
WHEN T1.GradeUpdate=0 THEN '--' WHEN T1.GradeUpdate=1 THEN '  ' WHEN T1.GradeUpdate=2 THEN '  ' 
WHEN T1.GradeUpdate=3 THEN '  '  END AS GradeUpdate,
T1.TargetPrice,T2.ReportDate  FROM    StockReview T1,Report T2,Company T3  where (T1.stockcode=@stockcode or T1.stockname=@stockcode)  and T1.ReportID = T2.ReportID   
and T2.CompanyID = T3.SourceID    order by T2.ReportDate desc
end
else   --       10 
begin
SELECT top 10 T1.ReportID,T1.StockCode,T2.ReportTitle,T3.SourceID,T3.CompanyName,T3.CompanyShortName,  
CASE  
WHEN T1.Grade=0 THEN '   ' WHEN T1.Grade=1 THEN '  '  WHEN T1.Grade=2 THEN '  ' WHEN T1.Grade=3 THEN '  '  
WHEN T1.Grade=4 THEN '  ' WHEN T1.Grade=5 THEN '  ' END AS Grade, 
 CASE 
WHEN T1.GradeUpdate=0 THEN '--' WHEN T1.GradeUpdate=1 THEN '  ' WHEN T1.GradeUpdate=2 THEN '  ' 
WHEN T1.GradeUpdate=3 THEN '  '  END AS GradeUpdate,
T1.TargetPrice,T2.ReportDate  FROM    StockReview T1,Report T2,Company T3  where T1.ReportID = T2.ReportID   
and T2.CompanyID = T3.SourceID    order by T2.ReportDate desc
end
GO
 
----    :  stockcode        
--   stockcode     ,        
IF exists (select * from SysObjects where name='sp_allreportlist' and type='p')
   drop procedure sp_allreportlist
go
CREATE PROCEDURE sp_allreportlist
@stockcode nvarchar(20)
as
  if(@stockcode!='')
begin
SELECT   T1.ReportID,T1.StockCode,T2.ReportTitle,T3.SourceID,T3.CompanyName,T3.CompanyShortName,  
CASE  
WHEN T1.Grade=0 THEN '   ' WHEN T1.Grade=1 THEN '  '  WHEN T1.Grade=2 THEN '  ' WHEN T1.Grade=3 THEN '  '  
WHEN T1.Grade=4 THEN '  ' WHEN T1.Grade=5 THEN '  ' END AS Grade, 
 CASE 
WHEN T1.GradeUpdate=0 THEN '--' WHEN T1.GradeUpdate=1 THEN '  ' WHEN T1.GradeUpdate=2 THEN '  ' 
WHEN T1.GradeUpdate=3 THEN '  '   END AS GradeUpdate,
T1.TargetPrice,T2.ReportDate  FROM (select   ReportID,StockCode,Grade,GradeUpdate,TargetPrice from  StockReview where stockcode=@stockcode or stockname=@stockcode) T1 left join Report T2 on  T1.ReportID = T2.ReportID  left join Company T3 
on T2.CompanyID = T3.SourceID      order by T2.ReportDate desc
end
else
begin
 SELECT   T1.ReportID,T1.StockCode,T2.ReportTitle,T3.SourceID,T3.CompanyName,T3.CompanyShortName, 
 CASE   WHEN T1.Grade=0 THEN '   '   WHEN T1.Grade=1 THEN '  '  WHEN T1.Grade=2 THEN '  '  
WHEN T1.Grade=3 THEN '  '   WHEN T1.Grade=4 THEN '  '  WHEN T1.Grade=5 THEN '  ' END AS Grade,  
 CASE  WHEN T1.GradeUpdate=0 THEN '--'   WHEN T1.GradeUpdate=1 THEN '  '  WHEN T1.GradeUpdate=2 THEN '  '  
 WHEN T1.GradeUpdate=3 THEN '  '   END AS GradeUpdate,  T1.TargetPrice,T2.ReportDate 
FROM StockReview T1 , Report T2,Company T3  
where  T1.ReportID = T2.ReportID and T2.CompanyID = T3.SourceID     
order by T2.Reportdate desc 
 
end
 GO
 
 
---    :  stockcode           
IF exists (select * from SysObjects where name='sp_allreportcount' and type='p')
   drop procedure sp_allreportcount
go
CREATE PROCEDURE sp_allreportcount
@stockcode nvarchar(20)
as
  if(@stockcode!='')
begin
SELECT   count(T1.ReportID)  FROM (select   ReportID,StockCode,Grade,GradeUpdate,TargetPrice from  StockReview where stockcode=@stockcode or stockname=@stockcode) T1 left join Report T2 on  T1.ReportID = T2.ReportID  left join Company T3 
on T2.CompanyID = T3.SourceID      
end
else
begin
 SELECT count( T1.ReportID)   FROM StockReview T1 , Report T2,Company T3  
where  T1.ReportID = T2.ReportID and T2.CompanyID = T3.SourceID     
end
 GO
 
exec sp_allreportcount '000001'
 
 
exec  sp_allreportlist ''  --      
 
 
 
exec  sp_reportpagelist '000001' ,10,10
---    :  ,   @endrecord-@num+1   @endrecord        
IF exists (select * from SysObjects where name='sp_reportpagelist' and type='p')
   drop procedure sp_reportpagelist
go
 
CREATE PROCEDURE sp_reportpagelist
@stockcode nvarchar(20),
@num int,   --  
@endrecord int   -- 0              
as
if(@stockcode!='')  --  @stockcode   
begin
select * from ( select top (@num) * from (
SELECT    top (@endrecord)  T1.ReportID,T1.StockCode,T2.ReportTitle,T3.SourceID,T3.CompanyName,T3.CompanyShortName,  
CASE  
WHEN T1.Grade=0 THEN '   ' WHEN T1.Grade=1 THEN '  '  WHEN T1.Grade=2 THEN '  ' WHEN T1.Grade=3 THEN '  '  
WHEN T1.Grade=4 THEN '  ' WHEN T1.Grade=5 THEN '  ' END AS Grade, 
 CASE 
WHEN T1.GradeUpdate=0 THEN '--' WHEN T1.GradeUpdate=1 THEN '  ' WHEN T1.GradeUpdate=2 THEN '  ' 
WHEN T1.GradeUpdate=3 THEN '  '   END AS GradeUpdate,
T1.TargetPrice,T2.ReportDate  FROM 
(select  ReportID,StockCode,Grade,GradeUpdate,TargetPrice from  StockReview where stockcode=@stockcode or stockname=@stockcode) T1 
left join Report T2 on  T1.ReportID = T2.ReportID  left join Company T3 
on T2.CompanyID = T3.SourceID      order by T2.ReportDate desc
) TT  order by TT.ReportDate) TTT order by TTT.ReportDate desc 
end
else  --         
begin
select * from ( select top (@num) * from (
SELECT    top (@endrecord)  T1.ReportID,T1.StockCode,T2.ReportTitle,T3.SourceID,T3.CompanyName,T3.CompanyShortName,  
CASE  
WHEN T1.Grade=0 THEN '   ' WHEN T1.Grade=1 THEN '  '  WHEN T1.Grade=2 THEN '  ' WHEN T1.Grade=3 THEN '  '  
WHEN T1.Grade=4 THEN '  ' WHEN T1.Grade=5 THEN '  ' END AS Grade, 
 CASE 
WHEN T1.GradeUpdate=0 THEN '--' WHEN T1.GradeUpdate=1 THEN '  ' WHEN T1.GradeUpdate=2 THEN '  ' 
WHEN T1.GradeUpdate=3 THEN '  '   END AS GradeUpdate,
T1.TargetPrice,T2.ReportDate  FROM 
(select  ReportID,StockCode,Grade,GradeUpdate,TargetPrice from  StockReview) T1 
left join Report T2 on  T1.ReportID = T2.ReportID  left join Company T3 
on T2.CompanyID = T3.SourceID      order by T2.ReportDate desc
) TT  order by TT.ReportDate) TTT order by TTT.ReportDate desc 
 
end
 GO

좋은 웹페이지 즐겨찾기