Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
nicklarge
Starting Member
40 Posts |
Posted - 2012-09-05 : 10:47:12
|
Hello SQL Server Forums.In my report I have 2 multi-valued parameters. One is Year, and the other is Month. The Year runs as 2010, 2011, 2012 ... 2015, and the month parameter runs as 01, 02, 03 ... 12. The report itself is for parallel periods so the user could select 2010, 2011 and 2012 in the year dropdown, then 05, 06 and 07 in the month drop down. In my query I have the SQL as an expression, which, at some point needs to state (in the case of the values selected in this description) : AND [Process Date Fiscal Year Month] IN (201005, 201006, 201007, 201105, 201106, 201107, 201205, 201206, 201207)The reason that I want to do it this way is because my table is partitioned on Process Date Fiscal Year, and so then I could gain the performance benefit of partition elimination through this method.How do I take the 2 multivalued parameters and write an expression that concatenates the items so they appear as shown?Any suggestions please?Regards, Nick. |
|
nicklarge
Starting Member
40 Posts |
Posted - 2012-09-05 : 11:51:42
|
So I managed to do it through a culmination of writing code to produce the text that I wanted, along with putting the reference to the code in the SQL expression for the dataset.Here is the code that I wrote. I went to Reports -> Report Properties -> Code and built the code in there.Public Function GetFiscalYearMonthList() as String dim yr_cnt as integer, mth_cnt as integer dim returnstring as string yr_cnt = 0 mth_cnt = 0 returnstring = "" for yr_cnt = 0 to (Report.Parameters!FiscalYear.Count() - 1) 'fetch each month value for mth_cnt = 0 to (Report.Parameters!FiscalMonth.Count() - 1) returnstring = returnstring & Report.Parameters!FiscalYear.Value(yr_cnt) & Report.Parameters!FiscalMonth.Value(mth_cnt) if mth_cnt < (Report.Parameters!FiscalMonth.Count() - 1) then returnstring = returnstring & ", " end if next mth_cnt if yr_cnt < (Report.Parameters!FiscalYear.Count() - 1) then 'add the comma for the next value returnstring = returnstring & ", " End if Next yr_cnt Return returnstringEnd Function When I tested the code I created a new test report that had 3 textboxes. The first and second boxes were populated with the values that I put into the Year and month parameters;=Join(Parameters!FiscalYear.Value, ", ")... and=Join(Parameters!FiscalMonth.Value, ", ")respectively.The 3rd box has an expression:=Code.GetFiscalYearMonthList()which then goes to the code and grabs the values that I selected in the format YYYY1MM1, YYYY1MM2, YYYY2MM1, YYYY2MM2 ... as required. Hope that this helps someone in future.The only regret that I have here is that Microsoft did not allow for looping constructs in the SSRS expressions, or, for that matter, improve the code box in SSRS from the multiline textbox that they have left there to rot, versus, say, the kind of scripting environment that they have in SSIS script components that has been the "standard" of today.Nick. :) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-05 : 21:55:18
|
quote: Originally posted by nicklarge Hello SQL Server Forums.In my report I have 2 multi-valued parameters. One is Year, and the other is Month. The Year runs as 2010, 2011, 2012 ... 2015, and the month parameter runs as 01, 02, 03 ... 12. The report itself is for parallel periods so the user could select 2010, 2011 and 2012 in the year dropdown, then 05, 06 and 07 in the month drop down. In my query I have the SQL as an expression, which, at some point needs to state (in the case of the values selected in this description) : AND [Process Date Fiscal Year Month] IN (201005, 201006, 201007, 201105, 201106, 201107, 201205, 201206, 201207)The reason that I want to do it this way is because my table is partitioned on Process Date Fiscal Year, and so then I could gain the performance benefit of partition elimination through this method.How do I take the 2 multivalued parameters and write an expression that concatenates the items so they appear as shown?Any suggestions please?Regards, Nick.
why not create them as a single parameter then?other ways how are you going to correlate between corresponding members selected from two dropdowns.if you want them to be used together i cant understand why you should have them as separate parameters in first place------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
nicklarge
Starting Member
40 Posts |
Posted - 2012-09-06 : 17:44:19
|
Visakh,Because it is a parallel period report the user should select the year and months separate, otherwise they would need to select the cartesian product of Year * Month which would just annoy them. For example, if the user wanted parallel periods for 2008, 2009, 2010 and 2011 for months 4, 5, 6, 10, 11 and 12 they would need to select 2008/04, 2008/05, 2008/06 ... 2008/12, 2009/04 ... which would open it to human error if they missed one, and also annoy them because they would have to click on 4 * 6 (20) checkboxes; as well as the list of possible months to click would be quite big at 4 * 12 (48) possibilities, and growing. There is also a requirement for fiscal week so 4 * 52 weeks = 208 possibilities ... that would be daunting. Thanks for the suggestion though :) |
|
|
|
|
|
|
|