Question

I have a report that runs a stored proc:

EXEC ra_spProjectCalendar @Month, @Year, @ProjectID

ProjectID is A multi-select dropdown. When a single project is selected, it works fine. If I select multiple projects, I get the error:

"Must declare scalar variable "@ProjectID"

It works fine when I run it from the Data tab, however, when I put it into Preview mode I have problems.

Was it helpful?

Solution

I got something similar to work by constructing the query as an expression - in your example

="EXEC ra_spProjectCalendar @Month = '" & Parameters!Month.Value & "',@Year='" & Parameters!Year.Value & "',@ProjectID = '" &  Join(Parameters!ProjectID.Value, ",") & "'"

Some code in the target SP splits the multi-select string into a temporary table which is used in joins to create output.

I can't remember why we ended up doing it this way - it was right at the start of our move to SSRS and things have moved on a bit since - but it may have been the problem you describe.

OTHER TIPS

I had the same error occur: Must declare scalar variable.

I realise now the first thing to check is that when you enter the query as text , or the stored proc as a stored proc type, that ssrs automatically creates the paramter entry in the parameters tab of the dataset properties. If it doesn't create them, it can't read your query properly.

In my case I was using OPENQUERY to call an analysis services cube and referencing the fieldnames which contain a lot of square brackets. Unfortunately SSRS loves to reformat your code so that nicely formated "[Measures].[SomeMeasure]" turns into this ugly escape character mess [[Measures]].[Somemeasure]]]

If you edit that query in another tool then re-copy it back to ssrs, then ssrs can't read that syntax! Even though it generates it! So remove all the extra square brackets and replace the double quotes and boom it works again and generates your parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top