Welcome to Spipp.net server Sign in | Join | Help

Kaisa's blog

On Reporting Services, Sharepoint, dotText and Larp

Stripping domain name when using User!UserID in a report

Sometimes you might need to know just the short name of a user when rendering a report in Reporting Services. Using the built in parameter User!UserID will give you the whole AD login name, typically domain\username.

For the last customer I've worked with, we needed to take the username and use it against a SQL server table to find a different ID that was to be used in our reports. After a bit of googling, I came up with the following:


SELECT e.EMPLID, e.NAME
FROM EmployeeTable e INNER JOIN
UserData u ON e.USERID = u.ID
WHERE (e.DATAAREAID LIKE 'wis') AND (u.ID = RIGHT(@UserID, LEN(@UserID) - CHARINDEX('\', @UserID)))

The last bit will take the whole name, domain\username, count at what character index the \ is, and then use that as the len(ght) parameter to get just the characters on the right side of the \.

Even if you don't need to use it against a table, you can still use the code in SQL to extract the username.

Published 15-04-2005 01:05 by kaisa
Filed Under:
New Comments to this post are disabled
SkinName:iroha_Blog2
Powered by Community Server, by Telligent Systems