Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you retrieve NT username from SQL

Status
Not open for further replies.

MaffewW

Technical User
Apr 9, 2002
438
0
0
GB
Hi, I need to try and return the NT username. I've done a keyword search and I dont think theres a way of doing it. I can get the station name, db login etc, we use 3rd party software and everyone uses the same SQL server login so this is no good. Can it be done?
 
thanks for the link, I really needed it from SQL though as its part of a query

I am fairly sure it cant be done
 
Hi

It can be done

Lookup System_User in Books online

Sample Stored procedure follows:

/*
Returns the user's current record
*/
CREATE PROCEDURE spUser AS
DECLARE @NTUser varchar(50)
SET @NTUser = RTrim(SubString(System_User,Patindex('%\%',System_User)+1,50))
SELECT Top 1 * from tbUsers WHERE RTrim(fdNTUserID) = @NTUser

Regards

sadcow
 
MikePP,

The stored procedure works if you have the table tbUsers. However, I don't think most of us have such a table on our servers.

MaffewW,

You are correct about being unable to obtain the NT login name from SQL Server if connected using SQL authentication. You must use NT authentication to obtain the NT Login. Terry L. Broadbent - DBA
SQL Server Page:
If you want to get the best answer for your question read faq183-874.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top