问题
I have an SSRS report that prints address labels, 30 to a page, in 3 columns.
I've created the report similar to the instructions found here
Rarely do I have to print exactly 30 labels. So, to conserve paper and money, I would like to add a parameter to this report with numbers 1-30 to decide which location on the page to begin printing.
If I had already printed 16 labels on a page, I could then select 17 in the parameter and my results would begin printing in the 17th label on the page.
If I can use the parameter to add a number of blank rows to my result set, I could accomplish this. Is this possible?
回答1:
I'm not sure this is best solution but see this query below
DECLARE @StartColumn INT = 6
;WITH CTE
AS (
SELECT *
,ROW_NUMBER() OVER (ORDER BY q.value) AS [rowNum]
FROM (
values('A'),('B'),('C'),('D'),('E'),('F'),('G'),('H'),('I'),('J'),('K'),('L')
) q (value)
)
SELECT CASE
WHEN CTE.rowNum > @StartColumn THEN CTE.value
ELSE NULL
END AS [Value]
FROM CTE
you will get result like this
Then run it's will show blank when null value in report (I think you use Group in report for print multiple rows)
回答2:
I was faced with a similar problem, eg selecting which label to print, but also need to print more than 1 label per client. My problem is that I cannot access the SQL (we use cubes). I used SSRS 2012 with SharePoint. It's not pretty, but it does work.
I had 1 dataset in my report. I had 14 labels - 7 down & 2 across. Each label is set up as it's own tablix.
The tablix are numbered 1 to 14, starting from the top left. So, 1-7, down the left "column" & then 8-14 from the top of the right "column".
Annoyingly the parameter values start from 0, so they are numbered 0-13 Each tablix is set up to be fitered by the specific parameter value, eg tablix 1 is set up to be filtered by parameter value 0, tablix 2 is filtered by parameter value 1, tablix 3 is filtered by parameter value 2, tablix 4 is filtered by parameter value 3, etc.
I had to print the data twice in the label so I used 2 text boxes within my tablix.
Create parameter
Users would be using the Client Id (a 6 digit number) as the parameter value. I created a parameter called ClientID. For the prompt I put "Replace 000000 for each label required. 000000 = blank label"
Under the General option, I:
- changed Data type to Text
- enabled Allow blank value ("")
- enabled Allow multiple values
- set Select parameter visibility to Visible
Available Values
- left as None
- Default Values
- selected Specify values
- clicked Add and set the Value to 00000 I did this 14 times (so I have a default value of 000000 for each label)
Create tablix
I then created a tablix for each label. They all pointed to my dataset (imaginatively called "DataSet1"). They consisted of one cell. This matched the height and width of the printable area of my label.
Create text box
I added my first text box inside the tablix cell. I made it slightly smaller that the width of the tablix and just down from the top of the tablix.
The created the second text box & moved it down until it suited my needs. It used the same formula as the first text box. (remember I needed to print the client name twice).
I used a lookup to the dataset in my report. Yes, in spite of the fact that the tablix was already based on this dataset.
For the first label, the formula for both textboxes was:
=lookup(Parameters!ClientID.Value(0),
Fields!ID.Value,
UCase(Fields!Surname.Value),
"DataSet1")
& ", " &
lookup(Parameters!ClientID.Value(0),
Fields!ID.Value,
Fields!Given.Value,
"DataSet1")
Create filter for tablix
I also had to apply a filter to each tablix, so it would print the client information selected via the parameter.
On the Tablix Properties under the Filters option + click Add + from the expression, I selected my ClientID + from the Operator, I selected In + in the Value, I clicked the Fx button to create the formula =Parameters!ClientID.Value(0)
Do not display default parameter value
Obviously if you leave the parameter value as the default (000000), it will print this.
The only way I could prevent this, was using the Font colour (I couldn't get Visibility to work).
+ Right click on the Text Box
+ Select Text Box Properties
+ Click on Font options
+ Under the Colour, click the Fx button
+ Use this formula:
=iif(Parameters!ClientID.Value(0)="000000", "White", "Black")
For subsequent labels
For the second label, I indexed the value in the brackets, eg (0) to (1) for both text box formulas and also for the filter, eg
=lookup(Parameters!ClientID.Value(1),
Fields!ID.Value,
UCase(Fields!Surname.Value),
"DataSet1")
& ", " &
lookup(Parameters!ClientID.Value(1),
Fields!ID.Value,
Fields!Given.Value,
"DataSet1")
and in the Tablix Properties filter,
=Parameters!ClientID.Value(1)
and in the Text Box Font formula
=iif(Parameters!ClientID.Value(1)="000000", "White", "Black")
I then indexed this number for each subsequent label, so the last label (label 14), the values were:
=lookup(Parameters!ClientID.Value(13) etc
and in the Tablix Properties filter,
=Parameters!ClientID.Value(13)
and in the Text Box Font formula =iif(Parameters!ClientID.Value(13)="000000", "White", "Black")
So, when users run the report, they replace the 000000, 000000, 000000, etc with the appropriate Client Id
回答3:
Chanom got me on the right track, my solution was to create my dataset query as shown in the example below.
declare @cnt int = 1
declare @string varchar(max) = ''
declare @varID varchar(max) = cast(@paramID as varchar(max))
IF @paramStartLocation > 1
WHILE @cnt < @paramStartLocation
BEGIN
set @string = @string + 'select null as Column1
,null as Column2
,null as Column3
,null as Column4
,null as Column5
,null as Column6
UNION ALL
'
set @cnt = @cnt + 1
END
set @string = @string + 'SELECT [TableName].[Column1]
, [TableName].[Column2]
, [TableName].[Column3]
, [TableName].[Column4]
, [TableName].[Column5]
, [TableName].[Column6]
FROM [TableName]
WHERE [TableName].[IDColumn] in ('+@varID+')'
exec(@string)
Here @paramStartLocation is the label slot that begins getting printed and the "null" records are displayed as blank in the report. Chanom's solution works to skip records and display blank instead, my solution needed to not skip records but add X number of blank records.
来源:https://stackoverflow.com/questions/39041738/is-there-a-way-to-add-a-blank-row-to-an-ssrs-dataset-based-on-parameter