我正在运行SSRS报告,我的数据源是FetchXML。
不幸的是,使用FetchXML,您无法运行存储过程或函数。
可以通过几种不同的方式提出这个问题:
这是我的查询,将转换为fetchxml:
SELECT systemuser.fullname AS 'fullname',
usersettings.calendartype AS 'calendartype',
usersettings.uilanguageid AS 'uilanguageid'
FROM filteredsystemuser AS systemuser
INNER JOIN filteredusersettings AS usersettings
ON systemuser.systemuserid = usersettings.systemuserid
WHERE systemuser.systemuserid = dbo.Fn_finduserguid()
这里是 dbo.fn_finduserguid()
的来源SET ansi_nulls ON
go
SET quoted_identifier ON
go
ALTER FUNCTION [dbo].[Fn_finduserguid] ()
returns UNIQUEIDENTIFIER
AS
BEGIN
DECLARE @userGuid UNIQUEIDENTIFIER
--- test whether the query is runing by priviledged user with user role of CRMReaderRole
--- if it is dbo, we trust it as well.
--- There is an issue in SQL. If the user is a dbo, if it not member of any role
IF ( Is_member('CRMReaderRole') | Is_member('db_owner') ) = 1
BEGIN
SELECT @userGuid = Cast(Context_info() AS UNIQUEIDENTIFIER)
END
IF @userGuid IS NULL
BEGIN
SELECT @userGuid = s.systemuserid
FROM systemuserbase s
WHERE s.domainname = Suser_sname()
END
RETURN @userGuid
END
答案 0 :(得分:1)
创建一个选择函数作为列的视图应该没有问题。
Create view vFindUserGuid
As
Select dbo.Fn_finduserguid() as userguid
您的查询可以像普通表一样使用视图
SELECT systemuser.fullname AS 'fullname',
usersettings.calendartype AS 'calendartype',
usersettings.uilanguageid AS 'uilanguageid'
FROM filteredsystemuser AS systemuser
INNER JOIN filteredusersettings AS usersettings
ON systemuser.systemuserid = usersettings.systemuserid
WHERE systemuser.systemuserid = (select userguid from vfinduserguid)