将功能应用于视图(Apply a function to a View)

编程入门 行业动态 更新时间:2024-10-17 20:24:59
将功能应用于视图(Apply a function to a View)

我在SQL 2012中工作。我曾经在SQL 2008 R2上的单个表视图上使用交叉应用命令。 我正在做一个多表视图,并尝试使用交叉应用,我收到一个错误。 我不确定连接是否导致问题,或者它是否与CROSS APPLY相关。

以下是以前的工作原理:

CREATE VIEW [dbo].[AttributeValues_VW] AS select userProfileID, Name, Item from dbo.AttributeValues cross apply dbo.udf_Split(Value,',') as Item; GO

这是我正在尝试的:

Create View [dbo].[DistrictManager_VW] AS Select Distinct AV.UserProfileID, AV.Name, AV.Value, UP.EmailAddress, MR.RoleID From Mup_UserAttributeValue AV Join Mup_UserProfile UP on AV.UserProfileID=UP.UserProfileID Join Mup_Role MR on MR.UserProfileID=AV.UserProfileID Join Main_Form MF on MF.[Primary Email]=UP.EmailAddress Where RoleID=267 cross apply dbo.udf_Split(AV.Value,',') as Item; Go

I am working in SQL 2012. I used to use a cross apply command on a single table view on SQL 2008 R2. I'm doing a multiple table view and trying to use the cross apply and I am receiving an error. I'm not sure if the join is causing the issue or if it's related to the CROSS APPLY.

Here is what used to work:

CREATE VIEW [dbo].[AttributeValues_VW] AS select userProfileID, Name, Item from dbo.AttributeValues cross apply dbo.udf_Split(Value,',') as Item; GO

Here is what I am trying:

Create View [dbo].[DistrictManager_VW] AS Select Distinct AV.UserProfileID, AV.Name, AV.Value, UP.EmailAddress, MR.RoleID From Mup_UserAttributeValue AV Join Mup_UserProfile UP on AV.UserProfileID=UP.UserProfileID Join Mup_Role MR on MR.UserProfileID=AV.UserProfileID Join Main_Form MF on MF.[Primary Email]=UP.EmailAddress Where RoleID=267 cross apply dbo.udf_Split(AV.Value,',') as Item; Go

最满意答案

cross apply在from子句中:

Create View [dbo].[DistrictManager_VW] AS Select Distinct AV.UserProfileID, AV.Name, AV.Value, UP.EmailAddress, MR.RoleID From Mup_UserAttributeValue AV Join Mup_UserProfile UP on AV.UserProfileID = UP.UserProfileID Join Mup_Role MR on MR.UserProfileID = AV.UserProfileID Join Main_Form MF on MF.[Primary Email] = UP.EmailAddress cross apply dbo.udf_Split(AV.Value, ',') as Item; Where RoleID = 267;

但是,您似乎没有使用Item 。 应该在select子句中。

cross apply goes in the from clause:

Create View [dbo].[DistrictManager_VW] AS Select Distinct AV.UserProfileID, AV.Name, AV.Value, UP.EmailAddress, MR.RoleID From Mup_UserAttributeValue AV Join Mup_UserProfile UP on AV.UserProfileID = UP.UserProfileID Join Mup_Role MR on MR.UserProfileID = AV.UserProfileID Join Main_Form MF on MF.[Primary Email] = UP.EmailAddress cross apply dbo.udf_Split(AV.Value, ',') as Item; Where RoleID = 267;

However, you don't seem to be using Item. Should that be in the select clause.

更多推荐

本文发布于:2023-08-03 13:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用于   视图   功能   View   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!