02/15/2019
by Marlon Ribunal
2 Comments

SQL Server 2017 Reporting Services: The Basics Part 4

Note: I’ve been meaning to start a series on the basics of SQL Server Reporting Services (SSRS). The last time I did this was on a book on SQL Server 2012 Reporting Services published by Packt. SSRS has since evolved into a better reporting platform with the addition of KPI’s, mobile reports, etc.

We’re now in Part 4 of our SSRS Basics Series, in which we cover simple parameterized report. Before we proceed, if you are a total newbie to SSRS and you’ve never created nor deployed an SSRS report, Part 1 shows you how to install SSRS. Part 2 shows you how to create a simple table report. And, Part 3 shows you how to deploy that report to the SSRS Report Server.

First thing first: Create the following stored procedure. This contains the dataset of our next report.

CREATE PROCEDURE OrderTotalQuery ( @vOrderTotal FLOAT = NULL )
 AS 
 BEGIN
    --Set Default OrderTotal Value
    IF @vOrderTotal IS NULL
       SET @vOrderTotal = 1000 ;
    SELECT c.CustomerName
         , SUM( sol.Quantity * sol.UnitPrice ) AS OrderTotal
    FROM Sales.Orders so
    JOIN sales.OrderLines sol
      ON so.OrderID = sol.OrderID
    JOIN sales.Customers c
      ON so.CustomerID = c.CustomerID
    GROUP BY c.CustomerName
           , sol.OrderID
    HAVING SUM( sol.Quantity * sol.UnitPrice ) >= @vOrderTotal
    ORDER BY OrderTotal DESC ;
 END ;

We have one parameter in this stored procedure, called vOrderTotal. We are assigning it the NULL marker as a default. But let’s aside this NULL for our next post. For now, take note that it’s there and that we will use it later in the next post.

Basically, what this query does is return the Customers with equal to or more than X amount, where X = variable @vOrderTotal.

What a parameter does is it allows us to specify a value on runtime. We don’t need to go back in the database and hard-code the value. But of course, you already know that.

Create the Report

Open the existing project. Go back to Part 2 here if you’re not sure what I am referring to. Create a new report and name it rdl_SSRSTutorial_001_OrderTotalQuery.

Create the Dataset

Create a new dataset under the Shared Dataset in the project. Again, if you’re not sure how to do that, check the Part 2 of this series. Name it ds_SSRSTutorial_001_OrderTotalQuery. For the data source, we use the same Data Source that we previously created, DS_SSRSTutorial_001. We’re not creating a new Data Source because we’re basically connecting to the same database.

Select Stored Procedure for the Query Type. And select the OrderTotalQuery stored procedure that we created above.

Select the Parameters in the pane on the left. You may notice that the parameter of our stored procedure has been automatically detected. Let’s leave it as is for now. We’re going to go back here in the next post.

Click OK.

Parameterized Report

Drag the Table component into the report canvas. Like what we’ve seen in Part 2, dragging a table component into the designer displays the Dataset Properties dialog. Let’s name our report’s dataset as rpt_table_ds_SSRSTutorial_001_OrderTotalQuery. Use Shared Dataset and select the ds_SSRSTutorial_001_OrderTotalQuery dataset.

Again, you may notice that our parameter is detected automatically.

Click OK.

Preview the Report

Let’s preview the report to make sure it’s working. Input 10000 in the Order Total box. Click the View Report button.

You may notice that the parameter is named v Order Total, which is automatically copied from the parameter of our stored procedure. Let’s rename that by removing the letter v.

Rename the Report Parameter

Click the Design tab. Make sure you select the the design tab, or you won’t see the Report Data option in the View menu. Navigate to Menu > View > Report Data or Click CTRL + ALT + D.

In the Report Data pane, navigate to Parameters > vOrderTotal. Right-click the parameter and select the Parameter Properties. Select the General properties if it’s not already selected.

Change the Prompt. Remove the letter v. Click OK.

Build and Deploy the Parameterized Report

Build and deploy both the dataset and report. If you’re not sure how to do that, refer to Part 3 of our series which covers report deployment.

Parameterized Report in Action

Here’s our basic parameterized report in action.

Let’s make our parameter intelligent in the next installment of our SQL Server 2017 Reporting Services Basics Series. Next is about Range Value Parameter.

02/08/2019
by Marlon Ribunal
2 Comments

SQL Server 2017 Reporting Services: The Basics Part 3

Note: I’ve been meaning to start a series on the basics of SQL Server Reporting Services (SSRS). The last time I did this was on a book on SQL Server 2012 Reporting Services published by Packt. SSRS has since evolved into a better reporting platform with the addition of KPI’s, mobile reports, etc.

This is the Part 3 of our SQL Server 2017 Reporting Services (SSRS) Basics Series. You can find Part 1 here and Part 2 here. Part 3 covers report deployment.

You may remember that in part 1 we set up and installed the SSRS Web Service in the localhost http://localhost/reportserver. In our case, the hostname is the computer name (instead of the literal localhost).

You may want to check your SSRS Web Server URL on your Report Server Configuration Manager (you can find it in your start menu).

There are two ways of deploying a report:

  • Visual Studio Project Deployment
  • Manual Upload and Setup of the Report Files
Project Properties

In part 2, we created a report server project. Open the project on Visual Studio. Build the solution if you haven’t done so. Navigate to Build > Build Solution. You can also build via the context menu of the Solution in the Solution window (see the screenshot below for reference).

In the Solution Explorer window ( press CTRL + ALT + L if it’s not showing), select the project (we named it SSRSTutorial_001 last time). Right-click the project and select Properties in the context menu.

That will display the Project Properties dialog box. You can set up different Configurations depending on your target environment (e.g., Production, QA, Dev, UAT, etc). Let’s pretend we’re deploying this to Production so we choose Release as our configuration. Pay attention to the TargetServerURL property. Make sure that it’s the same as the Web Service URL in the Report Configuration Manager.

Project Deployment

Click OK. Select the Project again, right-click and select Deploy.

You may also deploy the individual components one by one.

A successful deployment message and other related info are now displayed in the Output window (press CTRL + ALT + O if it’s not showing).

Go to the Web Portal (http://localhost/reports). Check the Report Server Configuration Manager if you’re not sure of the URL. Click Browse to navigate to the deployed folders. You should have three folders containing the different components of our reports: Data Source, Dataset, and the Reports Definition Language (RDL) File. You can set the name of these folders in the project properties dialog box (see above). The properties are called TargetDataSourceFolder, TargetDatasetFolder, and TargetReportFolder respectively.

Manual Deployment

Let’s create three new folders in the Web Portal. Let’s name these folders with the same name above, plus the prefix term manual to distinguish them from the folders we deployed via Visual Studio.

In the Web Portal, click New and select Folder. Create three folders: Manual Data Source, Manual Dataset, and Manual SSRSTutorial_001.

Create The Data Source

Click the first folder, Manual Data Source, to open it. Click New and select Data Source. Name this data source as Manual_DS_SSRSTutorial_001. Select Microsoft SQL Server for the Connection Type. Input the following in the Connection String (you can basically copy this from the Data Source property of your solution in Visual Studio):

Data Source=./;Initial Catalog=WideWorldImporters

Leave the Credentials as is. Make sure to check the option Enable this data source. You may want to test your connection to make sure you’re connecting to the SQL Server. Click Create.

Upload the Dataset and Report

Click the Manual Dataset folder to open it. Click Upload from the menu. Navigate to your project bin files. In my case, that’s C:\Users\Marlon.Ribunal\Documents\Visual Studio 2017\Projects\SSRSTutorial_001\SSRSTutorial_001\bin\Release. Select the
Dataset file (ds_SSRSTutorial_001.rsd) . Navigate back Home in the web portal. Upload the Report file (rdl_SSRSTutorial_001.rdl) to the Manual SSRSTutorial_001 folder.

Set up the Dataset

Navigate to the Manual Dataset folder. Select the ds_SSRSTutorial_001 dataset or the ellipses on the top right-hand corner and select Manage. Select Data Source on the panel.

You get a warning that says, We can no longer find this data source. If it was moved, choose it from its new location. Click the ellipses under the warning. That will open a dialog box showing all the folders in the web portal.

Select the Manual Data Sources folder. Select the
Manual_DS_SSRSTutorial_001data source. Click Apply.

Set up the Report

Navigate back to Home and select the Manual SSRSTutorial_001 folder. Click the ellipses on the top right-hand corner of the report file. Select Manage. Select Shared Datasets from the panel.

You will also get a warning that says, We can no longer find this dataset. If it was moved, choose it from its new location. Click the ellipses under this warning. Select the Manual Dataset folder. Then select the ds_SSRSTutorial_001 dataset. Click Save.

Viewing the Reports

Navigate to Home. Select the SSRSTutorial_001 folder. Select rdl_SSRSTutorial_001. This contains the report we deployed via Visual Studio Project Deployment. Navigate back to Home. Now, select the
Manual SSRSTutorial_001 folder. This contains the report we set up manually. Select rdl_SSRSTutorial_001.

You should be able to view both reports.

And we’re done with the deployment part. We’ll set more properties in the future posts. For the meantime, stand by for the next installment of this SSRS Basics Series, basic parameterized report.

02/01/2019
by Marlon Ribunal
4 Comments

SQL Server 2017 Reporting Services: The Basics Part 2

Note: I’ve been meaning to start a series on the basics of SQL Server Reporting Services (SSRS). The last time I did this was on a book on SQL Server 2012 Reporting Services published by Packt. SSRS has since evolved into a better reporting platform with the addition of KPI’s, mobile reports, etc.

This is the Part 2 of our SQL Server 2017 Reporting Services (SSRS) Basics Series. You can find Part 1 here. We are going to create our first report – a basic Table Report. Before we do that, you should have the following tools installed on your local machine or laptop:

These are the basic tools we need to create our first report in SSRS. You actually have two (2) basic options for designing reports: Visual Studio Report Designer (see above) and the standalone Report Builder which you can download here. We are using Visual Studio in this series. You can explore other tools for authoring reports here.

Basic Components of a Report

First thing first: There are three (3) basic components of a report. These are Data Source, Dataset, and Report Definition Language (RDL) file.

  • Data Source – In SSRS context, the data source is where your data is coming from. In our case, it is the local instance of SQL Server 2017. The data source includes connection string, data provider, and the credentials for accessing the source.
  • Dataset – We define a dataset in SSRS with a query command. The result set returned by our query will be displayed on our table report.
  • Report Definition Language (RDL) File – RDL is a dialect of Extensible Markup Language (XML). The report itself is in the form of this XML-like language. Don’t worry if you do not know how to write RDL. The report designer will translate our report components into RDL behind the scene so we don’t have to do that ourselves.
Shared Components

You have two (2) options on how to utilize the Data Source and Dataset: Shared or Embedded. The difference between Shared data source and dataset and their Embedded counterparts is reusability. As the adjective indicates, Shared can be used by different reports. You define them once and use them multiple times.

A report with an embedded data source and dataset will work right off the bat when uploaded in the report server without explicitly telling the report service what data source and dataset to use. If you have a separate, shared data source and dataset, you have to explicitly tell the report service which data source and dataset are used for the specific report. In this series, we are going to use a shared data source and dataset.

Basic Table Report

Let’s create our first report – a basic table report. Fire up your Visual Studio. Create a new project called SSRSTutorial_001 or any name you prefer. Use the Report Server Project template provided by Visual Studio. Click OK.

That should open Visual Studio designer. We’re going to create the components in this order: Data Source, Dataset, and Report Definition Language (RDL) file.

Data Source

In the Solution Explorer window (Press CTRL+ALT+L if the window is not showing, or Menu > View > Solution Explorer), right-click the Shared Data Sources folder and select Add New Data Source. That will display the Shared Data Source Properties dialog box.

In the Name field, let’s input DS_SSRSTutorial_001. Select Microsoft SQL Server for the source Type (should be the default).

Click the Edit button in the Connection String. That should bring up the Connection Properties dialog box. The Microsoft SQL Server (SqlClient) should be good for the data source and we’ll leave it like that. Leave the Authentication as Windows Authentication.

For the Server Name, input localhost or “./” (without the quotes) to point to our local instance of SQL Server. Select the WideWorldImporters database. Click the Test Connection button to make sure you’re connecting to the source. Click OK. There is no need to set the Credentials because we are using Integrated Security with Windows Authentication. Click OK. That will create our Shared Data Source (.rds file).

You may notice that the Connection Properties dialog created the Connection String for us.

Dataset

Creating the dataset is similar to how we created the data source. Right-Click the Shared Datasets folder in the Solution Explorer. and select Add New Dataset. Let’s name it ds_SSRSTutorial_001.

For the Data Source, select the data source we just created above, DS_SSRSTutorial_001 . It should be selected by default because it is the only data source created in our project at this point.

Select Text for the Query Type. Let’s borrow the dataset I used in my Creating Bar Graph In SQL Server 2017 Using R post. Copy and paste the following TSQL Code into the Query box, then click OK.

SELECT sg.StockGroupName
	 , SUM( il.LineProfit ) AS LineProfit
FROM Sales.InvoiceLines il
JOIN Warehouse.StockItems si
  ON il.StockItemID = si.StockItemID
JOIN Warehouse.StockItemStockGroups sis
  ON si.StockItemID = sis.StockItemID
JOIN Warehouse.StockGroups sg
  ON sis.StockGroupID = sg.StockGroupID
GROUP BY sg.StockGroupName ;
Report Definition Language File

Now we’re ready to create our first basic table report. Right-Click the Reports folder in the Solution Explorer. Your instinct is probably select the first option in the context menu, Add New Report. But the option runs the Report Wizard. We’re going to skip the wizard and create a report from scratch. Select Add > New Item. That will display the Add New Item dialog box. Select the Report template and name the report rdl_SSRSTutorial_001. Click Add.

You should now see the Report Designer with an empty canvas in your Visual Studio.

At this point, you should now have the three basic components in your Solution: Data Source, Dataset, and Report Definition.

Design the Report

Let’s design our report. Drag the Table component from the Toolbox window into the empty report canvas. If the Toolbox window is not showing, press CTRL+ALT+X. Or you can open it from the Menu > View > Toolbox.

Dragging the Table component into the canvas will display the Dataset Properties dialog box. Let’s name our report dataset as rpt_table_ds_SSRSTutorial_001. Tick Use a Shared Dataset radio button; and select the dataset we created above, ds_SSRSTutorial_001. Click OK.

Click on the table to show the bar around the table designer. Right-Click the bar on top of the header on the third column, then select Delete Columns. We don’t need a third column for now.

Place your cursor in the data cell in the first column. That will display the little Table icon in the top corner of the cell. Click the icon and select StockGroupName.

Do the same for the other cell and select LineProfit.

The report designer should now display something like this:

Click the Preview tab to display the preview of our report:

And there you go. You just created your first basic table report. In the next post, we will deploy this report to our report server. Stand by.