December 2, 2004 at 3:39 pm
Hi there,
Is any way to display the currrent user's login?
For example, using user_name() will display the current db user. If there are a lot of db_owners will always display dbo.
I would like to see something like domain\winuser in SQL.
Any help will be appreciated.
Gabriela
December 2, 2004 at 4:09 pm
Use system_user. It returns domain\user.
You can put it in a user defined function to be able to use it in a query :
my function returns a varchar(50) to be sure it does not truncate the user names. If your user names are short, you can put a different value
CREATE FUNCTION udfFindCurrentUser
()
RETURNS varchar(50)
AS
BEGIN
DECLARE @User varchar(50)
SET @User=SUBSTRING(LTRIM(RTRIM(system_user)),LEN('TECHNOPOS\')+1,50)
RETURN (@User)
END
Hopes this help
Erik
December 3, 2004 at 7:24 am
Also, if you only need the 'user' part of 'domain\user' -
select right (system_user,len(system_user) -charindex ('\',system_user))
December 3, 2004 at 7:30 am
Thank you all.
Gabriela
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply