Reporting

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

reporting-services

#reporting-
services
Table of Contents
About 1

Chapter 1: Getting started with reporting-services 2

Remarks 2

Examples 2

Installation or Setup 2

Chapter 2: Check for NULL or Blank 3

Examples 3

Check for NULL or Blank fields 3

Check for NULL or Empty fields - shortcut 3

Chapter 3: IF expression 5

Examples 5

If points field value is greater than 10 then display good else average 5

Using IIF to Screen for Division by Zero 5

AND / OR IF condition 5

Chapter 4: Switch Expression 7

Examples 7

Changing text color using switch condition 7

Credits 8
About
You can share this PDF with anyone you feel could benefit from it, downloaded the latest version
from: reporting-services

It is an unofficial and free reporting-services ebook created for educational purposes. All the
content is extracted from Stack Overflow Documentation, which is written by many hardworking
individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official reporting-
services.

The content is released under Creative Commons BY-SA, and the list of contributors to each
chapter are provided in the credits section at the end of this book. Images may be copyright of
their respective owners unless otherwise specified. All trademarks and registered trademarks are
the property of their respective company owners.

Use the content presented in this book at your own risk; it is not guaranteed to be correct nor
accurate, please send your feedback and corrections to [email protected]

https://riptutorial.com/ 1
Chapter 1: Getting started with reporting-
services
Remarks
This section provides an overview of what reporting-services is, and why a developer might want
to use it.

It should also mention any large subjects within reporting-services, and link out to the related
topics. Since the Documentation for reporting-services is new, you may need to create initial
versions of those related topics.

Examples
Installation or Setup

SQL Server Reporting Services can typically be installed with SQL Server installation media. An
installation of SQL Server will be required, either locally or on a server.

Starting with SQL Server 2008 R2, SSRS has the option to integrate with SharePoint instead of
running a separate website.

Read Getting started with reporting-services online: https://riptutorial.com/reporting-


services/topic/2652/getting-started-with-reporting-services

https://riptutorial.com/ 2
Chapter 2: Check for NULL or Blank
Examples
Check for NULL or Blank fields

This line of code demonstrate how to check if a specific field is NULL or has blank value

=IIF(IsNothing(Fields!UserEmail.Value) OR Fields!UserEmail.Value = "",


"Empty", "Not Empty")

This line of code checks if the field is NULL

IsNothing(Fields!UserEmail.Value)

This line of code checks if the field contains blank value ""

Fields!UserEmail.Value = ""

Check for NULL or Empty fields - shortcut

To get a shorter version of the Null or Empty check, use an "= Nothing" comparison.

Iif(Fields!UserEmail.Value = Nothing, "Null or Empty", "Not Null or Empty")

The "= Nothing" will check simultaneously against Null or Empty, giving a more compact
expression. This works for String, Numeric, and Boolean. From MSDN:

Nothing represents the default value of a data type. The default value depends on whether the
variable is of a value type or of a reference type.
A variable of a value type directly contains its value. Value types include all numeric data
types, Boolean, Char, Date, all structures, and all enumerations. A variable of a reference
type stores a reference to an instance of the object in memory. Reference types include
classes, arrays, delegates, and strings. For more information, see Value Types and Reference
Types.
If a variable is of a value type, the behavior of Nothing depends on whether the variable is
of a nullable data type. To represent a nullable value type, add a ? modifier to the type
name. Assigning Nothing to a nullable variable sets the value to null.

String will equate to Nothing if they are null or the empty string "".

Numerics will equate to Nothing if they are 0.

Booleans will equate to Nothing if they are False.

For a full list of the types and default values, check the (current) MSDN pages for Nothing.

Read Check for NULL or Blank online: https://riptutorial.com/reporting-services/topic/6626/check-

https://riptutorial.com/ 3
for-null-or-blank

https://riptutorial.com/ 4
Chapter 3: IF expression
Examples
If points field value is greater than 10 then display good else average

We have a set of data

We would like to see

by using the following expression in the detail textbox. we can achieve the Remark

=IIF(Fields!Points.Value>=10,"Good","Average")

Using IIF to Screen for Division by Zero

The IIF statement can be used in expressions to screen for division by zero:

=IIF(Fields!PossibleZero.Value=0,0,Fields!Denominator.Value/IIF(Fields!PossibleZero.Value=0,1,Fields!Po

SSRS does not short circuit IIF arguments. Therefore, using a single IIF function to screen for
division by zero will have no effect and give an #ERROR value.

Instead, a pair of nested IIF statements can be used. The outer IIF controls the value returned in
the case of division by zero, 0 in the example above. The inner IIF is a "dummy" value that
prevents the engine from actually performing a division by zero in this case.

AND / OR IF condition

https://riptutorial.com/ 5
Sometimes a complex IF condition is needed.

Let's take and example, Assuming we have the following raw data:

ItemID Item Name Item Status

1 Item 1 Tentative

1 Item 1 Pending

1 Item 1 Approved

The Goal is:

Let's assume our business user ask to see which items are not approved and which are approved.
Tentative and Pending items are considered as Not Approved.

IF Condition Example:

=IIF((Fields!ItemStatus.Value = "Tentative") Or (Fields!ItemStatus.Value = "Pending")


,"Not Approved", "Approved")

The results:

Read IF expression online: https://riptutorial.com/reporting-services/topic/6118/if-expression

https://riptutorial.com/ 6
Chapter 4: Switch Expression
Examples
Changing text color using switch condition

Let's assume we have an entity status field with 3 options

• Tentative
• Pending
• Approved

Our goal is to show different color for each status as follow: Tentative will be Red Pending will be
Orange Approved will be Green

The switch condition:

=Switch(Fields!ItemStatus.Value = "Tentative","Red",
Fields!ItemStatus.Value = "Pending", "Orange",
Fields!ItemStatus.Value = "Approved", "Green")

The pattern is:

=Switch([Condition statement] , [Value if True],


[Condition statement] , [Value if True],
[Condition statement] , [Value if True])

The second , sign starts a new condition. No , sign is needed for the last condition.

Results:

Read Switch Expression online: https://riptutorial.com/reporting-services/topic/6765/switch-


expression

https://riptutorial.com/ 7
Credits
S.
Chapters Contributors
No

Getting started with


1 Community, DForck42
reporting-services

Check for NULL or


2 idclaar, Silagy
Blank

3 IF expression bitnine, Hari, Silagy

4 Switch Expression Silagy

https://riptutorial.com/ 8

You might also like