Thursday, December 13, 2012

Lesson 1: Create a Simple SSRS report (Tutorial).



Agenda of the tutorial is to create a simple SSRS report. Once we are done with the tutorial you can see that it is so easy.

Open Business Intelligence Development Studio (BIDS)
Select Menu File -> New -> Project.












New project window should appear. Ensure you have Business Intelligence Projects selected on the left side (Project types). Select Report Server Project from templates window.

Type name (SampleReportingProject), select location, Solution Name usually is the same as project name and should be updated when you type project name (name text box). Click ok to create new SSRS project.


















Now that you have new SSRS Project created you should be able to view its content in solution explorer pane.
Next step will show you how to setup Shared Data Source.
Data source contains a connection string which is used to connect to your source of data. "Shared" just means you can re-use it for different reports.
To set up shared data source in Solution Explorer pane right click "shared data source" and click "Add new data source".












We should see Shared Data Source Properties window, change Name and click Edit button which will display "Connection Properties" window. In here you need to specify server name.
We will use UserWindowsAuthentication (you could use SQL authentication if you have SQL username/password). Next go to Select or enter a database name. If previous options are set correctly and you have permissions and connectivity this drop down box should show you available databases.
Once you select database in our case “Movies”, we can double check connectivity by clicking TestConnection button and if is ok then select OK button.










We can see that the connection string is auto generated using our input from previous window. Click ok to finish creating the shared data source.





















In Solution Explorer you should see your new Data Source which in my case is called “SampleReportingProjectDS.rds”.












Now we can Add New Report. In solution explorer right click reports folder and select Add New Report, then select New Item. 

NOTE: "Add New Report" (with *) also allows you to create a report but using an SSRS wizard which we won't be using in this tutorial. My best practice recommendation is to create report templates and then copy/paste into new report. You will save yourself a lot of repetitive work.














In "Add New Item" window we have two options to create Report we can just select Report or use Report Wizard. In this case we will use Report item (without wizard).
At the bottom we need to type report name as “SampleReport.rdl”.

















Now we can see that the report gets created and opened in design view.









Before creating dataset, create sample database Movies and run the below script to create the table we will be using.


/****** Object:  Table [dbo].[Movies] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Movies](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Title] [varchar](50) NULL,
[ReleaseDate] [datetime] NULL,
[Genre] [nvarchar](50) NULL,
[Price] [numeric](18, 0) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Movies] ON
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (1, N'Sangam', CAST(0x00009F9800000000 AS DateTime), N'U', CAST(100 AS Numeric(18, 0)))
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (2, N'Hum', CAST(0x0000915400000000 AS DateTime), N'UA', CAST(200 AS Numeric(18, 0)))
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (3, N'Sagar', CAST(0x00009F9800000000 AS DateTime), N'UA', CAST(200 AS Numeric(18, 0)))
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (4, N'Saudagar', CAST(0x00009F9800000000 AS DateTime), N'UA', CAST(100 AS Numeric(18, 0)))
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (5, N'Avatar', CAST(0x00009F9800000000 AS DateTime), N'U', CAST(400 AS Numeric(18, 0)))
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (6, N'Inception', CAST(0x00009F9800000000 AS DateTime), N'U', CAST(400 AS Numeric(18, 0)))
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (7, N'Devils Advocate', CAST(0x00009F9800000000 AS DateTime), N'A', CAST(400 AS Numeric(18, 0)))
INSERT [dbo].[Movies] ([ID], [Title], [ReleaseDate], [Genre], [Price]) VALUES (8, N'Blood and Wine', CAST(0x00009F9800000000 AS DateTime), N'A', CAST(400 AS Numeric(18, 0)))
SET IDENTITY_INSERT [dbo].[Movies] OFF


Now we need to create Data Set. A dataset contains Query String (in our case SQL query) which is executed at run-time and results are stored in the dataset and used by the report. 
To create new dataset open "Report Data" pane if it is not there use view menu. Right click datasets folder and click Add Dataset.














In the Dataset Properties fill in dataset name and click New button next to "data source" drop down box.























Data Source properties window is displayed and now we can use our shared data source that we created at the beginning by select it in "Use shared data sourced reference" drop down box. Click Ok.


















Next select Query Designer to setup query string.























Into Query Designer put your SQL query and click ok. (SQL Editor can help you generate your SQL query)



















Make sure if you have Name typed and you selected right Data source which we added in previous step and you can see your SQL query. Then click OK.























Finally we can see that your Dataset is visible in Report Data pane which the fields we selected.





















Your Data Set is ready. Now we can create simple report table. Open Toolbox (use view menu or icon on toolbar). 
Drag and drop a text box and a table item into design area.

















To place our fields from data set we can drag and drop the field or click on empty cell and in the right top corner a small rectangle should appear; click one of the fields and it will appear in the report table.











You can format the table by selecting a cell or entire row or column. Right clicking and going to properties. To view all available properties select a cell (row or column) and press F4 which will display properties pane. 
Finally to run the report click preview tab.
See below the end result.


No comments:

Post a Comment