首页 新闻 会员 周边 捐助

sql归纳

0
[已关闭问题]


use FundDb_Server
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/*********封闭式基金的分页显示****************/
ALTER procedure [dbo].[up_GetCloseFundList]
 @p_PageSize int= 30,
 @p_PageIndex int= 1,
 @p_filter nvarchar(200),
 @p_TotalRecords int output
as
set nocount on
select @p_TotalRecords=count(*) from CloseFund where symbol like @p_filter
create table #tmp
(
 rowid int,
 Symbol varchar(50)
)

create table #getStr
(
 rowid int,
 Symbol varchar(50),
 FundShortName nvarchar(100),
 StartDate smalldatetime,
 EndDate smalldatetime,
 IPODate smalldatetime,
 Category nvarchar(50),
 [Name] nvarchar(50),
 CompanyName nvarchar(50),
 CustodainName nvarchar(50)
)

insert into #tmp select ROW_NUMBER() over (order by Symbol desc) as rowid, Symbol from CloseFund where symbol like @p_filter

select * into #gStr from(
select
 rowid,
 t.Symbol,
 FundShortName,
 convert(varchar(10),StartDate, 121) as StartDate,
 convert(varchar(10),EndDate, 121) as EndDate,
 convert(varchar(10),IPODate,121) as IPODate,
 fc.CategoryName as Category,
    m.[Name],
 F.CompanyShortName as CompanyName,
 cd.CompanyShortName as CustodainName
from #tmp t
inner join CloseFund c on c.Symbol collate SQL_Latin1_General_CP1_CI_AS=t.Symbol
left join FundCompany F on F.CompanyCode=c.CompanyId
left join Custodian cd on cd.CompanyCode=c.CustodianId
left join FundCategory fc on fc.CategoryCode=c.Category
left join FundManager fm on c.Symbol=fm.Symbol
left join ManagerList m on m.ManagerId=fm.ManagerId) g

select * from #gStr

declare @Symbol varchar(6)
create  function  f_getStr(@Symbol)
returns varchar(100)
as
begin
    declare @ret varchar(100)
    set  @ret   =   ' '
    select   @ret   =   @ret+ ', '+[Name]   from   #gStr   where   Symbol   =   @Symbol
    set   @ret   =   stuff(@ret,1,1, ' ')
    return   @ret  
end

select rowid,Symbol,FundShortName,StartDate,EndDate,IPODate,Category,
f_getStr(Symbol) as ManagerName,CompanyName,CustodainName from #gStr
group by Symbol where rowid>@p_PageSize*(@p_PageIndex-1) and rowid<=@p_PageSize*@p_PageIndex
order by rowid
 
drop table #tmp

drop table #gStr

drop function f_getStr

GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

报这错:Msg 156, Level 15, State 1, Procedure up_GetCloseFundList, Line 56
Incorrect syntax near the keyword 'function'.
Msg 195, Level 15, State 10, Procedure up_GetCloseFundList, Line 68
'f_getStr' is not a recognized built-in function name.

 

my_exception的主页 my_exception | 初学一级 | 园豆:195
提问于:2009-09-28 14:19
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册