简体   繁体   English

SSRS多值参数错误

[英]SSRS Multi-Value Parameter Error

Goal: I have an SSRS report that uses a hidden parameter to capture the UserID, a multi-value drop-down parameter that displays Branches, and another multi-value parameter that will show Sales Reps related to those Branches. 目标:我有一个SSRS报告,该报告使用隐藏参数捕获UserID,使用多值下拉参数显示分支,并使用另一个多值参数显示与这些分支相关的销售代表。 The idea is that the user can only view Branches and Sales Reps where their UserID is equal to the name of the Branch. 这个想法是,用户只能查看其UserID等于分支名称的分支和销售代表。

Problem: If the user is given access to view the branches Chicago and New York, and selects only those Branches, the report runs fine. 问题:如果授予用户查看芝加哥和纽约分支的权限,并且仅选择那些分支,则报表运行良好。 Data is displayed for only those two Branches. 仅显示这两个分支的数据。

If the user selects only Chicago an error message is displayed. 如果用户仅选择芝加哥,则会显示错误消息。

If the user Selects only New York an error message is displayed. 如果用户仅选择纽约,则会显示错误消息。

If the user chooses 'SELECT ALL' the report displays data for all Branches (even Branches they should not have access to). 如果用户选择“全选”,报告将显示所有分支的数据(即使他们不应该访问的分支也是如此)。

ERROR MESSAGE: Conversion failed when converting the nvarchar value 'Chicago' to data type int. 错误消息: 将nvarchar值“ Chicago”转换为数据类型int时,转换失败。

I'm using a query in the Dataset, not a stored procedure. 我在数据集中使用查询,而不是存储过程。 Should I be using a stored procedure instead? 我应该使用存储过程吗?

I'm using an 'IN' operator in the WHERE CLAUSE: 我在WHERE条款中使用了“ IN”运算符:

WHERE ReportIDTable.ReportID = 1 
AND ReportIDTable.UserID = @UserID
AND ((Branch IN (@BranchID)) OR Branch = 9999)

I've tried using JOIN() and SPLIT() functions and I don't see a difference. 我尝试使用JOIN()和SPLIT()函数,但没有发现任何区别。

I've done a lot of research and I can't seem to get the issue solved. 我已经做了很多研究,但似乎无法解决问题。 Any help would be much appreciated! 任何帮助将非常感激!

The @BranchID parameter is set to TEXT already and is actually populated by another query. @BranchID参数已经设置为TEXT,并且实际上已由另一个查询填充。

SELECT 'ZZ <Untracked Sales>' AS ParentID
UNION
SELECT ParentID
FROM     ReportDistribution WITH (NOLOCK)
WHERE  (ReportID = 1) AND (ReportHierarchyID = 3)
GROUP BY ParentID

Main Dataset Query: 主要数据集查询:

SELECT 
commission_sale_history.invoice_year, 
commission_sale_history.invoice_month, 
branch.branch_description, 
commission_reps.division, 
commission_reps.rep_name, 
commission_reps.employee_id, 
commission_sale_history.customer_id, 
customer.customer_name, 
commission_sale_history.invoice_no, 
commission_sale_history.order_no, 
commission_sale_history.product_division, 
commission_sale_history.commission_type, 
commission_sale_history.sales, 
commission_sale_history.commission_cost, 
commission_sale_history.commission_amount, 
commission_sale_history.payment_date, 
commission_sale_history.invoice_date,
commission_sale_history.commission_rate, 
commission_sale_history.commission_split,
commission_reps.salary

FROM ((((commission_sale_history WITH (NOLOCK)
INNER JOIN commission_reps WITH (NOLOCK)
ON (commission_sale_history.branch_id = commission_reps.branch_id) 
AND (commission_sale_history.rep_id = commission_reps.rep_id)) 
INNER JOIN customer WITH (NOLOCK)
ON commission_sale_history.customer_id = customer.customer_id) 
INNER JOIN branch WITH (NOLOCK)
ON commission_sale_history.branch_id = branch.branch_id) 
INNER JOIN ReportIDTable WITH (NOLOCK)
ON commission_reps.rep_id = 
CASE WHEN CONVERT(int,ReportIDTable.Salesrep) = 999999
THEN commission_reps.rep_id ELSE
CONVERT(int,ReportIDTable.Salesrep) END)
LEFT JOIN invoice_hdr_salesrep WITH (NOLOCK)
ON invoice_hdr_salesrep.invoice_number = commission_sale_history.invoice_no
AND invoice_hdr_salesrep.salesrep_id = commission_sale_history.rep_id

WHERE ReportIDTable.ReportID = 1 
AND ReportIDTable.UserID = @UserID
AND ((Branch IN (@BranchID)) OR Branch = '9999')


AND commission_sale_history.rep_id IN(@SalesRepID)
AND commission_sale_history.invoice_date >= @InvoiceStartDate
AND commission_sale_history.payment_date
BETWEEN @PaymentFromDate AND @PaymentThroughDate
AND commission_sale_history.paid_in_full_flag = 'Y'
AND ISNULL(commission_sale_history.credit_matched_to_payment_flag,'Y') = 'Y'
AND commission_sale_history.product_division 
NOT IN ('Parts Sales', 'Rental', 'Forklift/Equipment', 'Service')
AND ISNULL(invoice_hdr_salesrep.primary_salesrep,'Y')='Y'

ORDER BY
commission_reps.rep_name,
customer.customer_id, 
commission_sale_history.invoice_no,
commission_sale_history.commission_type

I am assuming the BranchID is and int and its name a string and therefore you branches dataset looks something like this. 我假设BranchID为and int,其名称为字符串,因此您分支的数据集看起来像这样。

BranchID BranchName
1        Chicago
2        New York

In your parameter, make sure your Value is pointing to the 'BranchID' column and `Label' is pointing the 'BranchName' column. 在参数中,确保您的Value指向“ BranchID”列,而“标签”指向“ BranchName”列。

Once you have checked this, set your parameter value to be text (I know it's a number but try it....) 选中此选项后,将参数值设置为text (我知道这是一个数字,请尝试...。)

You don't need to use a stored proc, join or split, what you have should be fine. 您不需要使用存储的proc,join或split,就可以了。

If you still have problems, post the dataset query for both the main query and the parameter plus some sample output from each if possible. 如果仍然有问题,请发布针对主查询和参数的数据集查询,并在可能的情况下分别发布一些示例输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM