O'Reilly logo

SQL Server 2016 Reporting Services Cookbook by Robert C. Cain, Dinesh Priyankara

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Filtering data for the current user

SSRS Reports has the ability to use the identity of the current user as a built-in variable within the report. This means the user ID can be used as a filter for SQL queries against a data source, assuming the data source stores that same ID.

Getting ready

In order for this recipe to work correctly, we will need to add IDs to the database. We will modify the Dimension.Employee table within the WideWorldImportersDW database to hold a fictitious manager ID field. First, open SSMS and execute the following query against the WideWorldImportersDW database:

ALTER TABLE [Dimension].[Employee] 
ADD [ManagerID] NVARCHAR(50) 

Next, we will need to insert data into this column. In this example, you should replace the IDs shown ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required