Solved

SSRS Pass Multi-Value Parameter to Stored Procedure

Posted on 2014-11-28
5
330 Views
Last Modified: 2014-11-29
I was able to get some help with passing multi-value parameters from an SSRS report to a SP several months back, but now I have a follow up.

@StoreID is working fine but @GroupName gives me the following error 'Conversion failed when converting the varchar value 'Redemption' to data type int'

I'm using the same function for both and have never had any issues with other SP. I'm must be doing something wrong with the @GroupName.

ALTER PROCEDURE [dbo].[sp_GameScoring]

@BeginDate DateTime
,@EndDate DateTime
,@StoreID  varchar (1000)
, @GroupName varchar (1000)


AS




WITH GrossCollectedRank AS
	(
SELECT			ROW_NUMBER() OVER (ORDER BY SUM(GrossCollected)DESC) AS GrossCollectedRank
				, StoreID
				, StoreGameID
				, SUM(GrossCollected) AS GrossCollected
				,(CASE
						WHEN (SUM(CreditPlays) + SUM(BonusPlays) + SUM(CourtesyPlays)) = 0 
						THEN (GamePrice) 
						ELSE SUM(MoneyIN) /(SUM(CreditPlays) + SUM(BonusPlays) + SUM(CourtesyPlays)) 
						END) AS AvgPrice
				, Sum(Tickets) / Sum(GrossCollected) / 100 AS Payout

FROM            View_GrossGameSalesDetail

WHERE			StoreID IN (SELECT CAST(value as int) from dbo.ParmsToList(@StoreID,','))
				AND GroupName IN (SELECT CAST(value as int) from dbo.ParmsToList(@GroupName,','))
				AND (TransactionDate BETWEEN @BeginDate AND @EndDate)

GROUP BY		StoreID, StoreGameID, GamePrice
)
	


	SELECT	SM.StoreID
			, SM.StoreGameID
			, SM.GroupName
			, SM. MachineName
			, SM.ActiveDate
			, GC.GrossCollected
			, GC.GrossCollectedRank
			, GC.AvgPrice
			, GC.Payout

			
	FROM StoreMasterGameList SM
			JOIN GrossCollectedRank GC ON SM.StoreID = GC.StoreID and SM.StoreGameID = GC.StoreGameID
			

Open in new window

0
Comment
Question by:dk04
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:John_Vidmar
ID: 40470987
Line 30, below, is attempting to convert each element in the comma-delimited list contained in @GroupName into integer values.  Instead of a number, I suspect @GroupName contains the value Redemption.
AND GroupName IN (SELECT CAST(value as int) from dbo.ParmsToList(@GroupName,','))

Open in new window

0
 

Author Comment

by:dk04
ID: 40470990
Yes it does. It is one of the groups to choose from. In the table it is a varchar (100)
0
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 500 total points
ID: 40471644
Cool, so instead of attempting to convert to int, convert to varchar(100):
AND GroupName IN (SELECT CAST(value as varchar(100)) from dbo.ParmsToList(@GroupName,','))

Open in new window

0
 

Author Comment

by:dk04
ID: 40471702
It worked. Awesome! Thanks
0
 

Author Closing Comment

by:dk04
ID: 40471703
Perfect, just what I needed.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now