在 MS SQL Server 2012 SP1 中,当我执行时:
SELECT rt.RoleId, ur.RoleName, app.ApplicationName
FROM [TV_ClientPortal].[dbo].[UserRoleTie] rt
JOIN [TV_ClientPortal].[dbo].[UserRoles] ur
ON rt.RoleId = ur.RoleId
JOIN [TV_ClientPortal].[dbo].[Applications] app
ON app.ApplicationId = ur.ApplicationId
WHERE rt.UserId = 255 AND
('SalesCRM' IS NULL OR app.ApplicationName = 'SalesCRM')
我得到一排。现在我写了一个内联函数:
CREATE FUNCTION dbo.Func_GetRolesForUser
(
@UserId int,
@AppName varchar
)
RETURNS TABLE
AS
RETURN
(
SELECT rt.RoleId, ur.RoleName, app.ApplicationName
FROM [TV_ClientPortal].[dbo].[UserRoleTie] rt
JOIN [TV_ClientPortal].[dbo].[UserRoles] ur
ON rt.RoleId = ur.RoleId
JOIN [TV_ClientPortal].[dbo].[Applications] app
ON app.ApplicationId = ur.ApplicationId
WHERE rt.UserId = @UserId AND
(@AppName IS NULL OR app.ApplicationName = @AppName)
)
GO
但是当我执行
SELECT * FROM dbo.Func_GetRolesForUser(255, 'SalesCRM')
我没有得到任何结果。知道为什么会这样吗?我考虑过权限问题,但据我所知,我拥有执行该功能的完全权限。