Display current login

  • 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

  • Check Current Acivity window or try suser_sname

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_setu-sus_8kdh.asp

    Regards,Yelena Varsha

  • 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

  • Also, if you only need the 'user' part of 'domain\user' -

    select right (system_user,len(system_user) -charindex ('\',system_user)) 

  • 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