Solved

SSRS Pass Multi-Value Parameter to Stored Procedure

Posted on 2014-11-28
5
307 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

758 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

23 Experts available now in Live!

Get 1:1 Help Now