SQL Server Functions and views

Source: Internet
Author: User

-- Search fields to be set: expertname, expertdomain, hitcountsdata, workhistory, eduhistory, projecthistory, award, researchpaper, researchpapermonograph, expertallinfo
-- The Field expertallinfo is of the document type, and all other retrieval fields are of the phrase type.

-- 1. obtain expert experience
-- 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. obtain expert learning experience
-- 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. obtain expert project experience
-- 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. obtain experts' Awards
-- 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. obtain expert papers
-- 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. obtain expert Monographs
-- 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. all expert information
-- 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. create a view
-- drop view v_coworkplatformexico
Create view v_coworkplatformexico
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.