sql server 函數與視圖的使用

來源:互聯網
上載者:User

--需要設定的檢索欄位: ExpertName,ExpertDomain,hitCountsData,WorkHistory,EduHistory,ProjectHistory,Award,ResearchPaper,ResearchPaperMonograph,ExpertAllInfo
--其中欄位 ExpertAllInfo 為document類型,別的檢索欄位都為phrase類型

--1. 擷取專家工作經曆
-- drop function F_GetWorkHistory

create function F_GetWorkHistory(
   @ExpertId numeric(9)
)
returns varchar(8000)
as
begin
    declare @ret varchar(8000)
    select @ret = ''
      select @ret = @ret + isnull(workOrgnization,'') + ' ' + isnull(WorkPost,'') + ';' from xwcmworkHistory
      where objid = @ExpertId and objtype = 2045598757
    if(@ret is null)
 return ''
    return @ret
end
Go

--2.擷取專家學習經曆
-- drop function F_GetEduHistory
create function F_GetEduHistory(
   @ExpertId numeric(9)

)
returns varchar(8000)
as
begin
    declare @ret varchar(8000)
    select @ret = ''
      select @ret = @ret + isnull(EduSchool,'') + ' ' + isnull(ProfessionalName,'') + ';' from xWCMEduHistory
      where objid = @ExpertId and objtype = 2045598757
    if(@ret is null)
 return ''
    return @ret
end
Go

--3.擷取專家項目經曆
-- drop function F_GetProjectHistory
create function F_GetProjectHistory(
   @ExpertId numeric(9)

)
returns varchar(8000)
as
begin
    declare @ret varchar(8000)
    select @ret = ''
      select @ret = @ret + isnull(ProjectName,'') + ' '+ isnull(Post,'') + ' ' + isnull(Orgnization,'') + ' ' + isnull(Production,'') + ';' from xWCMProjectHistory
      where objid = @ExpertId and objtype = 2045598757
    if(@ret is null)
 return ''
    return @ret
end
Go

--4.擷取專家獲獎情況
-- drop function F_GetAward
create function F_GetAward(
   @ExpertId numeric(9)

)
returns varchar(8000)
as
begin
    declare @ret varchar(8000)
    select @ret = ''
      select @ret = @ret + isnull(AwardTitle,'') + ';' from XWCMAward
      where objid = @ExpertId and objtype = 2045598757
    if(@ret is null)
 return ''
    return @ret
end
Go

 

--5.擷取專家論文
-- drop function F_GetResearchPaper
create function F_GetResearchPaper(
   @ExpertId numeric(9)
)
returns varchar(8000)
as
begin
    declare @ret varchar(8000)
    select @ret = ''
      select @ret = @ret + isnull(researchPaperTitle,'') + ' ' + isnull(Author,'') + ' ' + isnull(Summary,'') + ' ' + isnull(PeriodicalName,'') + ' '
                         + isnull(PublishCompany,'') + ' ' + isnull(PeriodTime,'') + ' ' + isnull(Content,'') + ';' from xWCMresearchPaper
       where ResearchPaperId in (select ResearchPaperId from xWCMresearchPaperUser
            where objid = @ExpertId and objtype = 2045598757
       ) and researchPaperType = 0
      
    if(@ret is null)
 return ''
    return @ret
end
Go

--6.擷取專家專著
--drop function F_GetResearchPaperMonograph
create function F_GetResearchPaperMonograph(
   @ExpertId numeric(9)
)
returns varchar(8000)
as
begin
    declare @ret varchar(8000)
    select @ret = ''
      select @ret = @ret + isnull(researchPaperTitle,'') + ' ' + isnull(Author,'') + ' ' + isnull(Summary,'') + ' ' + isnull(PeriodicalName,'') + ' '
                         + isnull(PublishCompany,'') + ' ' + isnull(PeriodTime,'') + ' ' + isnull(Content,'') + ';' from xWCMresearchPaper
       where ResearchPaperId in (select ResearchPaperId from xWCMresearchPaperUser
            where objid = @ExpertId and objtype = 2045598757
       ) and researchPaperType = 1
      
    if(@ret is null)
 return ''
    return @ret
end
Go

--7.專家的全部資訊
--drop function F_GetExpertAllInfo
create function F_GetExpertAllInfo(
   @ExpertId numeric(9)
)
returns varchar(8000)
as
begin
    declare @ret varchar(8000)
    select @ret = ''
      select @ret = @ret + isnull(ExpertName,'') + '||' + isnull(ExpertDomain,'') + '||'      
       + dbo.F_GetWorkHistory(@expertid) + '||' + dbo.F_GetEduHistory(@expertid) + '||'
       + dbo.F_GetProjectHistory(@expertid) + '||' + dbo.F_GetAward(@expertid) + '||'
       + dbo.F_GetResearchPaper(@expertid) + '||' + dbo.F_GetResearchPaperMonograph(@expertid)      
      from XWCMExpert  where  ExpertId = @ExpertId
    return @ret
end
Go

--8. 建立視圖
--drop view V_CoWorkPlatFormExpert
create view V_CoWorkPlatFormExpert
as
select * ,dbo.F_GetWorkHistory(XWCMExpert.Expertid) as WorkHistory,dbo.F_GetEduHistory(XWCMExpert.Expertid) as EduHistory,
  dbo.F_GetProjectHistory(XWCMExpert.Expertid) as ProjectHistory,dbo.F_GetAward(XWCMExpert.Expertid) as Award,
  dbo.F_GetResearchPaper(XWCMExpert.Expertid) as ResearchPaper,dbo.F_GetResearchPaperMonograph(XWCMExpert.Expertid) as ResearchPaperMonograph,
  dbo.F_GetExpertAllInfo(XWCMExpert.Expertid) as ExpertAllInfo
from XWCMExpert

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.