问题
I have a number of SSRS Reports that are printing to dedicated Zebra Label printers where the printer is the default for the user. Each report is passed a parameter: Number_Of_Copies. In the application that calls this there can be 1 to any number of copies as a value for Number_Of_Copies. Somehow I need to product a report with however many copies are indicated (with page breaks between) and a field that indicates which sequence number the label is: "x of Number_Of_copies." This is apparently easier said than done. Is there a way in the SSRS Report itself (which is being called via a command line) to do this?
回答1:
Here's how you can do it...
Oh, and this is quite wordy but it's actually very simple..
First thing we need is your label report, which I assume you've got and I'll call it LabelA
for the purpose of this answer.
We need to edit this report so that it accepts 2 parameters (Copies
and CurrentCopy
). Add a text field with an appropriate expression to display this info e.g.
="Label " & Parameters!CurrentCopy.Value & " of " & Parameters!Copies.Value
Run this report and test it works by typing in numbers for the two parameters by hand. Once you know this is working OK, proceed.
Next we need another report which will act as our loop, so....
Create a new report, let's called it LabelA_Loop
(I know terrible name!)
In LabelA_Loop
, create dataset and call it dsLoop
Set the query for the dataset to something like this..
DECLARE @counter int = 1
DECLARE @t TABLE (RowNum int)
WHILE @Copies >= @counter
BEGIN
INSERT INTO @t SELECT @counter
SET @counter = @counter +1
END
SELECT * FROM @t ORDER BY rownum
(Of course you can use anything to create a list of numbers even have a big numbers table but this works and is easy to do...)
At this point, a parameter (@Copies
) will have been created automatically as it's required by your dsLoop
dataset.
Next step, add a table to the report.
Next, set the dataset property for the tablix (the table we just added) to be dsLoop
The table will only need to be one column wide and no header row so essentially we'll be left with a single 'cell'. Delete the row header and last two columns until you only have a single cell left.
In the table cell, insert a subreport and set the subreport property
to be our label report LabelA
.
In the parameters for the subreport, set Copies
to be your Copies
parameter and set CurrentCopy
to be the RowNum
field from your dsLoop
dataset.
You'll need to resize the cell to suit and set page breaks but that's it. The loop report takes a parameter Copies
which the dataset uses to generate the correct number of records. It will add one row per record in the dataset, each row will contain a label subreport and each subreport will be passed two parameters, the current copy and the total copies, which in turn are rendered in the final label.
来源:https://stackoverflow.com/questions/45617825/need-code-in-ssrs-to-create-multiple-serialized-copies-of-a-report-label