SQL Server Reporting Services
ContentsIntroduction to ssrs3Section A3How to install ssrs4Built in Expressions or functions used in ssrs10Types of Expressions10GLOBALS11OPERATORS11COMMON FUNCTIONS12SECTION B14EMBEDDED CODE FOR CELL COLORING (CONDITIONAL FORMATTING)15SHOW PERCENTAGES ON PIE CHART17T-SQL ISNULL FUNCTION EQUIVALENT20SHOW TICK/CROSS BOX INSTEAD OF TRUE/FALSE OR 1/020LINK POSTCODE OR ADDRESS TO GOOGLE MAPS22HANDLING DIVIDE BY ZERO ERROR24PARAMETER TO CONTROL ROW/COLUMN/TABLE VISIBILITY25ALTERNATING ROW COLORS IN A TABLE28HAVE TEXT ON MULTIPLE LINES IN A TEXTBOX28HOW TO HAVE INDENTED TEXT IN A REPORT29DEFINE A REPORT CONSTANT30DISPLAY A MESSAGE WHEN REPORT RESULT SET IS EMPTY31SETTING PARAMETERS DEFAULT VALUE ISSUE33CREATE A DRILL DOWN TABLE34DISPLAY ALL RECORDS ON ONE PAGE38HANDLING PAGING AND NO DATA ISSUE IN A SUB-REPORT41DISPLAYING DATA IN SSRS TOOLTIPS41HOW TO ADD AN ELSE TO SWITCH STATEMENT43CALCULATING RUNNING TOTALS44REPEAT TABLE HEADER ON EACH PAGE IN SSRS46
Introduction to ssrs
SSRS or SQL server Reporting Services which is also called Microsoft SQL reporting, is a component of the Microsoft BI stack.
The Microsoft Business Intelligence Stack mainly consists of SQL Database Engine, SSRS, SSAS, SSIS and other tools
SSRS is a set of readymade tools, which help you to create, deploy and manage reports.
You can extend reporting functionality using C# and VB as programming languages.
Microsoft SSRS or Business Intelligence SSRS, lets you create very rich reports (Tabular/Graphical/Interactive/free-form) from various data sources with rich data visualization (Charts, Maps, sparklines).
All these reports can be viewed via a web browsers.
SSRS allows are reports to be exported in various formats (Excel, PDF, word etc.)
SSRS allows reports to be delivered via emails or dropped to a share location in an automated fashion.
SSRS provides a host of security features, in order to control, who sees which reports etc.
How to install ssrsDouble-click the SQL Server2012 installationmedia. Click the Installationlink on the left to view the Installationoptions. Click the top linkNew SQL Serverstand-alone installationor add features to an existinginstallation.
Follow the SQL ServerSetup wizard until you get to the InstallationType screen. At that screen, selectAdd features to an existinginstance of SQL Server2012. ClickNextto move to the Feature Selectionpage. SelectReporting Services NativeandSQL ServerData Tools. If theManagement Toolshave not been installed, go ahead and choose them as well.
Continue through the wizard and reboot the computer at the end of the installationif instructed to do so.Configure Reporting ServicesIf you installed Reporting Services during the installationof the SQL Serverinstance, SSRSwill be configured automatically for you. If you install SSRS later, then you will have to go back and configure it as a subsequent step.ClickStart>All Programs>Microsoft SQL Server2012>Configuration Tools>Reporting Services Configuration Manager>Connecton the Reporting Services Configuration Connection dialog box.
On the left-hand side of the Reporting Services Configuration Manager, clickDatabase. Click theChange Databasebutton on the right side of the screen.
SelectCreate a new report server databaseand clickNext.
Click through the rest of the wizard accepting the defaults. This wizard creates two databases: ReportServer, used to store report definitions and security, and ReportServerTempDB which is used as scratch space when preparing reports for user requests.Now clickWeb ServiceURLon the left-hand side of the Reporting Services Configuration Manager. Click theApplybutton to accept the defaults. If theApplybutton has been grayed out, move on to the next step. This step sets up the SSRSweb service. The web service is the program that runs in the background that communicates between the web page, which you will set up next, and the databases.
The final configuration step is to select theReport ManagerURLlink on the left. Accept the default settings and clickApply. If theApplybutton was already grayed out, this means the SSRSwas already configured. This step sets up the Report Managerweb site where you will publish reports. You may be wondering if you also must install a web server on your computer. SQL Serverdoes not require that the Internet Information Server(IIS), the Microsoft web server, be installed to run Report Manager.
ClickExitto dismiss the Reporting Services Configuration Managerdialog box.
Built in Expressions or functions used in ssrsTypes of Expressions
Operators - Arithmetic, Comparison, Logical
Common Functions - Text, Date & Time, Math, Inspection, Program Flow, Aggregate, Financial, Conversion, Miscellaneous
Global expressions executes/works in Page Header and Footer parts only.ExecutionTimeshows date and time at when report executes
PageNumbershows page number of each and every page but allowed only in page header and footer
ReportNamedisplays name of the active report what name we have assigned to the active report
UserIdshows current user name like saxony/Prashant.RaiLanguagedisplays language like US-English
^power of*multiplication/divides two numbers and returns a floating point result\divides two numbers and returns a integer resultModdivides two numbers and returns remainder only+adds two numbers and concatenation for two strings-subtraction and indicates negative value for numeric values
Known operators :< >=
Likecompares two strings and return true if matched or else returns False. Ex: =Fields!Title.Value Like Fields!LoginID.Value
Iscompare two object reference variables Ex: = Fields!Title.Value Is Null
+ and &symbols uses for concatenation
Known:And, Not, Or
XorSELECT * FROM users where firstname = 'Prashant' XOR lastname = 'Rai'
AndAlsoFirst condition will check first and if it is true only, goes to next or else it won't need to check. Because our execution time is saving in a logical operation in which more conditions is combined using AndAlso function.
OrElsesame like above
The rest of the functions can be accessed by clicking on Expression on any report item, which looks like following:
The following section (pg.16-pg.46) will introduce you to some tips and tricks which are based upon, basic/inbuilt functions and expressions that we have in SSRS and which I have garnered over a period of time. This section is recommended for anyone who wants more out of standard SSRS expressions.
EMBEDDED CODE FOR CELL COLORING (CONDITIONAL FORMATTING)Bring up the Report Properties (by right clicking outside the report in Layout view)
Now go to the Code tab and write in this code:Function GetColour(ByVal Amount As Double) As StringIf Amount < 5000000 Then GetColour = "Red"ElseIf Amount >= 5000000 And Amount < 7500000 Then GetColour = "Orange"Else GetColour = "Green"End IfReturn GetColourEnd Function
Now Insert either of these formula into the Cells Colour Format=Code.GetColour(Fields!TotalDue.Value)=Code.GetColour(Me.Value)
SHOW PERCENTAGES ON PIE CHARTBring up the Chart Properties (Right Click the Chart object and select properties)
Now click theEditbutton for the Values section and go to the Point Labels tab
Uncheck Auto to get percentages on outside (the inside square of 9 put labels in Pie Chart, the other are on the outside) and check theShow point labelsboxNow the formula to enter into theData labeltext box is:=Sum(Value) / Sum(Value, "ChartDataset")In this case the formula is:=Sum(Fields!TotalDue.Value) / Sum(Fields!TotalDue.Value,"pRepSalesOrdersByMonth")And theLabel Stylebutton opens up the label formatting properties
And this is the final product
T-SQL ISNULL FUNCTION EQUIVALENTUsing the VB IIF Function use the following expression=IIF(Field!FieldName.Value Is Nothing, "Value for True", "Value for False")e.g.
SHOW TICK/CROSS BOX INSTEAD OF TRUE/FALSE OR 1/0Convert the Boolean (or 1/0) field to "R" for True / 1 and "Q" for False / 0You can do this either in SQL or using an IIF expressionSQL,CASEWHENBooleanField=1THEN'R'ELSE'Q'ENDASBooleanFieldIIF Expression=IIF(Fields!BooleanField.Value =True,"R","Q")The original field doesn't necessarily have to be Boolean e.g. Does final score pass exam:=IIF(Fields!FinalScore.Value >= 50,"R","Q")Now just format the textbox to Wingdings2
And this is what you get:
LINK POSTCODE OR ADDRESS TO GOOGLE MAPSOpen the textbox properties for the field you want to have the link:
And select theActiontab:
HANDLING DIVIDE BY ZERO ERRORBring up the Report Properties (by right clicking outside the report in Layout view)
Now go to the Code tab and write (or copy and paste) in