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 ...

Get SQL Server 2016 Reporting Services Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.