Groups | Blog | Home
all groups > sql server (alternate) > november 2005 >

sql server (alternate) : Parse Return value of SYSTEM_USER


laurenq uantrell
11/9/2005 7:27:10 PM
DECLARE @UserName nvarchar(100)
SELECT @UserName = SYSTEM_USER

value returned is "Domain\NTSignonName"
What I want is only "NTSignonName"

Is there a function to do this or an easy parse for this in SQL2000?

lq
laurenq uantrell
11/9/2005 7:46:43 PM
I know I can do:

DECLARE @UserNameWithDomain nvarchar(100)
SELECT @UserNameWithDomain = SYSTEM_USER

DECLARE @UserNameNoDomain nvarchar(100)
SELECT @UserNameNoDomain =
SUBSTRING(@UserNameWithDomain,CHARINDEX('\',@UserNameWithDomain)+1,100)

I'm hoping for something more aesthetic.
Erland Sommarskog
11/10/2005 8:31:05 AM
laurenq uantrell (laurenquantrell@hotmail.com) writes:
[quoted text, click to view]

I don't know if it's more esthetic, but parsename() is an alternative.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
AddThis Social Bookmark Button