Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to Get Windows UserName using SQL Query

Author  Topic 

sureshkk
Starting Member

21 Posts

Posted - 2011-11-30 : 09:30:47
Hi All,

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

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-11-30 : 10:14:19
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

21 Posts

Posted - 2011-11-30 : 10:19:38
Thanks for replay

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

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-11-30 : 10:57:47
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
   

- Advertisement -