SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to Get Windows UserName using SQL Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sureshkk
Starting Member

India
21 Posts

Posted - 11/30/2011 :  09:30:47  Show Profile  Reply with Quote
Hi All,

Is there any possibility to get windows login user name using SQL query?

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/30/2011 :  10:14:19  Show Profile  Reply with Quote
SUSER_NAME()
SUSER_SNAME()
SYSTEM_USER

Each serves a slightly different purpose - MSDN has the gory details.
Go to Top of Page

sureshkk
Starting Member

India
21 Posts

Posted - 11/30/2011 :  10:19:38  Show Profile  Reply with Quote
Thanks for replay

The above queries display SQL Server Login user,but i need windows login user name.
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/30/2011 :  10:57:47  Show Profile  Reply with Quote
If you are connecting to SQL Server using SQL authentication, I don't think SQL Server knows the AD user. You would have to get that information by querying the Windows (using a Powershell script invoked using xp_cmdshell, for example) or adding AD as a linked server (http://www.sqlservercentral.com/Forums/Topic265745-149-1.aspx#bm909492)

I have not done either of these, so I am unable to add more color. I am sure that if there is a better way, someone else would chime in.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000