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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to get user_id

Status
Not open for further replies.

pandatime

Programmer
Joined
Jan 29, 2010
Messages
92
Location
AU
Hi,

I am just trying to get an integer-based user_id (not the super-long hexadecimal one) from sql server.

I tried this but it gives me NULL:

SELECT USER_ID('myDomain\myLogin')

Any ideas? I don't want the hex version, or a string username. Just a simple integer id. I thought something like this existed in SQL Server but having a hard time finding it.

Thanks!
 
Aluminum, nice articles.

Pandatime, here are some examples from the link provided.

Code:
Set NoCount On

select CURRENT_USER as 'Current_User'
go
select user_name() as 'user_name'
go
Select user_id() as 'user_id'
go
DECLARE @session_usr char(30)
SET @session_usr = SESSION_USER
SELECT 'This session''s current user is: '+ @session_usr as 'Session_User'
GO
SELECT 'The current time is: '+ CONVERT(char(30), CURRENT_TIMESTAMP) as 'Current_TimeStamp'
GO



Thanks

John Fuhrman
 
Think I found what you are looking for

SELECT @@SPID AS 'ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name'
Here is the result set.
ID Login Name User Name
------ ------------------------------ ------------------------------
54 SEATTLE\joanna dbo

from msdn help:


Thanks

John Fuhrman
 
use tableschema;
go
create procedure t
if table t is not null
drop table t;
go
create table t
(id int as primary key not null auto_increment,
columnname int null,
columnname1 varchar(50) null,
columname2 date null);
go

That should work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top