The consumers of our data wish to be able to make stock and financial decisions from our data. Turning raw data into valuable information is one of the fortes of Master Data Services. In this part of discussion we shall be looking at ways and means of extracting valuable information for our reports and queries.
The folks at the clothing store want maximum flexibility when it comes to data extraction and reporting. They have defined 6 parameters that they wish to set
6) Neck Style
A report such as this, with many permutations of filtering, requires that the multi-select property of the parameter lists be set to ‘True’. We shall discuss more about the parameters when we enter SQL Server Reporting Services.
Prior to any report construction, we first shall construct a SQL Server Stored Procedure to extract the data necessary for the reports.
In creating the code, I utilized a string splitting routine which I found on the internet (over a year ago) and which I have modified many times to suit my needs.
The link to the ORIGINAL routine is :
The code for our Stored Procedure may be seen below:
/****** Object: StoredProcedure [dbo].[MultiSelect] Script Date: 02/02/2014 06:18:47 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
–IF OBJECT_ID(N’tempdb..#rawdata1′) IS NOT NULL
— DROP TABLE #rawdata1
–IF OBJECT_ID(N’tempdb..#rawdata2′) IS NOT NULL
— DROP TABLE #rawdata2
–IF OBJECT_ID(N’tempdb..#rawdata3′) IS NOT NULL
— DROP TABLE #rawdata3
–IF OBJECT_ID(N’tempdb..#rawdata4′) IS NOT NULL
— DROP TABLE #rawdata4
–IF OBJECT_ID(N’tempdb..#rawdata5′) IS NOT NULL
— DROP TABLE #rawdata5
–IF OBJECT_ID(N’tempdb..#rawdata6′) IS NOT NULL
— DROP TABLE #rawdata6
CREATE Procedure [dbo].[ClothingSales]
–declare @Size VARCHAR(4000)
–declare @Color VARCHAR(4000)
–declare @Type VARCHAR(4000)
–declare @Fabric VARCHAR(4000)
–declare @Gender VARCHAR(4000)
–declare @NeckStyle VARCHAR(4000)
–set @Size = ‘2,3,4,5,6,7’
–set @Color = ‘Green,Blue,Red’
–Set @Type = ‘Shirt,Dress,Pants’
–Set @Fabric = ‘Cotton,Cotton Blend’
–Set @Gender = ‘Male,Female’
–Set @NeckStyle = ‘Crew,Collared’
–Declare re-cycleable variables
declare @Comma CHAR(1)
DECLARE @Position INT
DECLARE @Substringg VARCHAR(4000)
Set @Comma = ‘,’
–Declare Table Variables
declare @SizeTable table
Size varchar(30) NOT NULL
declare @ColorTable table
Color varchar(30) NOT NULL
declare @TypeTable table
Type varchar(30) NOT NULL
declare @FabricTable table
Fabric varchar(30) NOT NULL
declare @GenderTable table
Gender varchar(30) NOT NULL
declare @neckStyleTable table
NeckStyle varchar(30) NOT NULL
SELECT @Position =1
IF (LEN(@Color)<1) OR @Color IS NULL RETURN
INSERT INTO @ColorTable(Color) VALUES(RTRIM(LTRIM(@Substringg)))
IF LEN(@Color)=0 BREAK
SELECT @Position =1
IF (LEN(@Size)<1) OR @Size IS NULL RETURN
INSERT INTO @SizeTable(Size) VALUES(RTRIM(LTRIM(@Substringg)))
IF LEN(@Size)=0 BREAK
SELECT @Position =1
IF (LEN(@Type)<1) OR @Type IS NULL RETURN
INSERT INTO @TypeTable(Type) VALUES(RTRIM(LTRIM(@Substringg)))
IF LEN(@Type)=0 BREAK
SELECT @Position =1
IF (LEN(@Fabric)<1) OR @Fabric IS NULL RETURN
INSERT INTO @FabricTable(Fabric) VALUES(RTRIM(LTRIM(@Substringg)))
IF LEN(@Fabric)=0 BREAK
SELECT @Position =1
IF (LEN(@Gender)<1) OR @Gender IS NULL RETURN
INSERT INTO @GenderTable(Gender) VALUES(RTRIM(LTRIM(@Substringg)))
IF LEN(@Gender)=0 BREAK
SELECT @Position =1
IF (LEN(@NeckStyle)<1) OR @NeckStyle IS NULL RETURN
INSERT INTO @NeckStyleTable(NeckStyle) VALUES(RTRIM(LTRIM(@Substringg)))
IF LEN(@NeckStyle)=0 BREAK
select Color as [Color] Into #rawdata1 from @ColorTable
select Size as [Size] Into #rawdata2 from @SizeTable
select [Type] as [Type] Into #rawdata3 from @TypeTable
select Fabric as [Fabric] Into #rawdata4 from @FabricTable
select Gender as [Gender] Into #rawdata5 from @GenderTable
select NeckStyle as [NeckStyle] Into #rawdata6 from @NeckStyleTable
— Return dataset to the report
[Safety Stock Level],
[Available to Outlet_Name],
where color_name in (select color from #rawdata1)
and size_name in (select Size from #rawdata2)
and [Type_name] in (select Type from #rawdata3)
and Fabric_Name in (select Fabric from #rawdata4)
and Gender_Name in (select gender from #rawdata5)
and [Neck Style_Name] in (select NeckStyle from #rawdata6)
—-Select * from #rawdata1
—-Select * from #rawdata2
—-Select * from #rawdata3
—-Select * from #rawdata4
— Select * from #rawdata5
— Select * from #rawdata6
Starting Up Reporting Services
We start by opening SQL Server Reporting Services and by creating a new Reporting Services project which we shall call ClothingDSS.
Click New and Project (as seen above). The New Project creation screen will appear.
Note that I have selected Reporting Services in the drop down box on the left and to create the report NOT utilizing the wizard. Being from the ‘Old School’ I do not utilize Report Builder nor the wizard, Sorry. Working without Report Builder provides added flexibility which most of us like to have.
As mentioned above, I call my Reporting Project “ClothingDSS”
Click OK to create your project.
For those new to Reporting Services, your working space should appear as shown in the screen dump below:
We start off by creating a Data Source. For those new to the term Data Source, I like to think of a Data Sources as a garden hose attached to the wall of a house. When turned on, it will bring data from the database (house) to my Reporting Services project. The other end of the hose, I use to place the data into a dataset. This could be synonymous with a watering can, i.e. pouring the water from the hose into a watering can and watering the flowers from there.
Right click on ‘Shared Data Sources’ and then click on Add New Data Source as may be seen in the screen dump above. The Shared Data Source Properties box will appear.
We merely give the data source a name. In our case ‘ClothingDSS’. What we now need to do is to create the actual connection back to our database. Click the ‘Edit’ button next to the connection string text box. The ‘Connection Properties’ box will appear.
We now configure our connection and test the connection (as we have done in past).
Click OK to release the ‘Test Connection succeeded’ text box. Click OK to free the Connection Properties Box and OK AGAIN to save our connection string. Your screen should now appear as in the screen dump below:
Note the data source in the upper right hand corner.
Right click on ‘Reports’ and choose ‘add’ and ‘new item’ as shown above.
The ‘Add New Item’ data capture screen will appear.
Chose ‘Report’ option and call your report ‘Clothing’ (as shown above). Click add.
Our Design Surface is now exposed.
Our ‘construction area’ is within the rectangle. Let’s stretch it out (see below)
Note that we have a lot of new options on the left hand side (parameters, Images etc.)
Should screen NOT show the Report Data menu, then click on VIEW (at the top) and click on the ‘Report Data’ menu. It should then appear where mine is.
Creating our first dataset
We shall start off creating our first data set. One for color. In total we shall eventually require seven datasets.
Right click on Dataset and select ‘Add Dataset’. We are going to create a ‘Color’ dataset.
The ‘Dataset Properties’ will appear. Change the name of the dataset from ‘DataSet1’ to Color. Then click the ’Use a dataset embedded in my report’ radio button. Your screen should now appear as shown below:
We now wish to ‘hook up’ the report to the database via our data connection. Click ‘New’ to the right of the ‘Data Source’ drop down.
In the name box we shall change the name of the data source from ‘DataSource1’ to ‘OurClothingDataSource’.
Click on the ‘Use shared data source reference’ radio button and click on the drop down box. You will see the data source that we have just created. Select it.
Your screen should now appear as shown below:
Click OK to complete the definition of our LOCAL Data Source. Please note that ‘OurClothingDataSource’ is only known within our small report. No other reports know about its existence. You will now find yourself back at the ‘DataSet’ screen.
We are now set to create our ‘Color’ dataset. Ensure that the TEXT radio button is selected as shown above. We are now going to add a bit of text in the text box (see below).
Click the ‘Refresh Fields’ button and then click on the ‘Fields’ tab in the upper left portion of this drop down box.
You will note that the ‘Color_name’ field is now shown within the box.
Click OK to close the ‘Fields’ box.
You will see that we now have a data set which will contain all of our colors KNOWN TO THE PRODUCTS WITHIN OUR TABLE.
It is left to the reader to create a similar dataset for Size, Type , Gender, Fabric and Neck Style. Please note that once we created the color dataset, that the ‘OurClothingDataSource’ will be available for you to utilize in creating the remaining 5 datasets.
After having completed creating the additional data sets, then your screen should appear similar to the one below:
Creating the parameters to be sent to the Store Procedure
We now wish to create the parameter drop down boxes, just like the ones shown below:
click on the ‘Parameter’ tab and click ‘Add parameter’
“Report Parameter Properties’ box will appear.
Change the name to ‘Color’, the ‘Prompt’ to Color, and CHECK the ‘Allow multiple values’ box.
Next click on the ‘Available Values’ tab.
Click the ‘Get values from a query’ radio button. Select ‘color’ from the from the data set drop down box.
Select ‘color_name’ from the Value field and from the Label field. The click OK.
It is left to the reader to create the necessary parameters for the remaining 5 datasets.
At the end of this part of the process, your screen should appear as shown below:
Creating the final dataset: The data matrix which will hold our data
Once again, we create a new dataset in a similar fashion to what we have done above. This time however, instead of entering free form text, we shall select the ‘Stored Procedure’ option and select the Stored Procedure created with the code listing above.
Your screen should look approximately like the screen dump below:
Click refresh fields, below the ‘Select or enter stored procedure name’ drop down box. The ‘Define Query Parameters’ pop up box will appear.
Simply click OK. Click the ‘Parameters’ tab as shown below:
Note that the Parameter Name is entered HOWEVER not its value.
We need to enter it. Click the ‘fx’ beside the color parameter. The expression box will open. Enter the following for @Color =JOIN(Parameters!Color.Value,”,”) See below.
It is left to the reader to complete the remaining 5 expressions changing the word ‘color’ for the respective parameter. Your completed screen should look like the one below:
Click OK to accept the parameter values.
Your screen should look like this.
Note that the fields in Clothing(1) are shown.
ONE CAVEAT, I have noticed at times, that the fields DO NOT populate automatically when one goes to the fields’ tab. (see below)
This is a ‘nasty’ and one has to manually enter the fields. See below:
Enter the field name.
While it is a pain, you will come right. The most important thing to note is that you must reset your parameter values to
See the screen dump below:
Setting up the Matrix
Click on the SSRS toolbox to bring up the tool box.
Drag a Matrix control onto the screen. Ensure that the ‘Properties’ box is showing on the bottom right side of your screen.
Find the Dataset name property and set it to Clothing1 or whatever you called your dataset(See below).
For our example right click on the ‘Column Group’ drop down box (above this text). Select ‘Delete Group Only’ (See below).
Now, double Click on the ‘RowGroups’. Set the grouping to be based upon ‘code’.
Click OK. We are now going to ‘fill in’ our data fields. Place ‘code’ in the first column of the first row as shown below.
When we do so, because the code is an integer, SQL Server Reporting Services want to SUM the column.
Simply right click on the field and follow the context menu as shown below.
The “sum” should no longer be there. In the box next to [Code] click the ellipsis. You will note all the other fields.
Select Color and add Color. We now need to add additional field ‘boxes’ as the matrix only gave us two by default.
Right Click on the top margin of the matrix as shown above in dark grey. Select ‘Insert Column’ and ‘Right’ (see below):
An additional column is inserted. The placement of the remaining columns is left to the reader to complete.
After all is said and done, your screen should resemble something like this (below).
Note that I just added a text box at the top and inserted the words “Our Sample MDS Report”
Running our report
To run and test our report, simply click upon the preview tab. The drop down parameter boxes will appear. The important point to note, is the flexibility that you have and the many permutations that you can create.
I also show (above) the size drop down box. Note that I have selected all and note that this too will form a comma delimited string once we pass to the next parameter. Upon completion of choosing your parameter arguments, click view report and you are done!! Amen!
Today we have seen
1) How to create a simple SQL Server Reporting Services report, to pull data from our Amsterdam database.
2) We have developed a SQL Server Stored Procedure to parse a string of parameter arguments passed through by the user. Multi selects make your reports more flexible for the end user.
3) You have seen how we construct our report, creating the parameter datasets, and then we created a data set devoted to the report matrix itself.
In the next part of this article, we shall be starting off in SQL Server Integration Services and we shall see how to create our daily load batch files to ensure that data is timeous loaded.
As always, should you have any questions, comments or concerns, please feel free to contact me at email@example.com