SQLServer(多语句表值函数代码)

SQLServer(多语句表值函数代码),第1张

SQLServer(多语句表值函数代码),第2张

代码如下:
set ANSI _ NULLSON
set quoted _ identifier on
GO
CREATE FUNCTION[DBO]。[UFNGETCONTACT INFORMATION](@ contact id int)
RETURNS @ retcontact INFORMATION TABLE
(
[contact id]int主键不为NULL,
[名字] [nvarchar](50) NULL,
[姓氏] [nvarchar](50) NULL,
[职务] [nvarchar](50) NULL,
[contact type][nvarchar](50)
BEGIN
DECLARE
@ first name[nvarchar](50)、
@LastName [nvarchar](50)、
@JobTitle [nvarchar](50)、
@ contact type[nvarchar](50);
-获取常用联系人信息
SELECT
@ contact id = contact id,
@FirstName = FirstName,
@ last name = last name
FROM[Person]。[Contact]
其中[Contact id]= @ Contact id;
SET @ job title =
CASE
-存在时检查员工
(SELECT * FROM[human resources])。[Employee] e
其中e .[contact id]= @ contact id)
然后(从[HumanResources]中选择[Title]
。[Employee]
其中[ContactID] = @ContactID)
-存在时检查供应商
(SELECT * FROM[Purchasing])。[VendorContact] vc
内部加入[Person]。vc上的[ContactType] ct
。[ContactTypeID] = ct。[ContactTypeID]
其中vc。[ContactID] = @ContactID)
然后(选择CT。[姓名]
来自[采购]。[VendorContact] vc
内部加入[Person]。vc上的[ContactType] ct
。[ContactTypeID] = ct。[ContactTypeID]
其中vc。[ContactID] = @ContactID)
-当商店存在时检查商店
(SELECT * FROM[Sales])。[store contact]sc
INNER JOIN[Person]。sc上的[ContactType] ct
。[ContactTypeID] = ct。[ContactTypeID]
其中sc。[ContactID] = @ContactID)
然后(选择CT。[销售部门]的[姓名]
。[store contact]sc
INNER JOIN[Person]。sc上的[ContactType] ct
。[ContactTypeID] = ct。[contact typeid]
WHERE[contact id]= @ contact id)
ELSE NULL
END;
SET @ contact type =
CASE
-存在时检查员工
(SELECT * FROM[human resources])。[Employee] e
其中e .[contact id]= @ contact id)
THEN ' Employee '
-检查供应商
是否存在(SELECT * FROM [Purchasing])。[VendorContact] vc
内部加入[Person]。vc上的[ContactType] ct
。[ContactTypeID] = ct。[ContactTypeID]
其中vc。[ContactID] = @ContactID)
然后是“供应商联系人”
-如果存在,则检查商店
(SELECT * FROM[Sales])。[store contact]sc
INNER JOIN[Person]。sc上的[ContactType] ct
。[ContactTypeID] = ct。[ContactTypeID]
其中sc。[ContactID] = @ContactID)
然后是“商店联系人”
-当存在时检查个人消费者
(SELECT * FROM[Sales])。[个人] i
其中I .[contact id]= @ contact id)
然后'消费者'
结束;
-如果@ContactID不为NULL,则将信息返回给调用方
,BEGIN
INSERT @ retContactInformation
SELECT @ contact id,@FirstName,@LastName,@JobTitle,@ ContactType
END;
退货;
END;

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » SQLServer(多语句表值函数代码)

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情