简体   繁体   中英

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. The idea is that the user can only view Branches and Sales Reps where their UserID is equal to the name of the Branch.

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.

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 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.

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.

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 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.

Once you have checked this, set your parameter value to be text (I know it's a number but try it....)

You don't need to use a stored proc, join or split, what you have should be fine.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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