CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    SQL Server - How to get the name of the logged in user?

    How do I get the name of the user executing a stored proc in the T-SQL in that proc?
    e.g.

    Code:
    ALTER PROCEDURE dbo.TakeOnClient
       (
       @Id uniqueidentifier
       )
    
    AS
      DECLARE @Username varchar(200)
    
      -- Get the current login that executes this proc
    
      -- Update the client table
      UPDATE dbo.Clients
          SET Owner = @Username
       WHERE Id = @Id
    
    RETURN
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Lightbulb Re: SQL Server - How to get the name of the logged in user?

    how about using this??

    Code:
    SELECT 'The current user is: '+ convert(char(30), SYSTEM_USER)

  3. #3
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: SQL Server - How to get the name of the logged in user?

    Or use:
    Code:
    SET Owner = SUSER_SNAME()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured