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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Passing USER_NAME() to SP_HELPUSER procedure

Author  Topic 

cshong
Starting Member

8 Posts

Posted - 2010-03-25 : 01:07:12
USER_NAME() is a function which return the user name of the current connected user.

I tried the following:

EXEC SP_HELPUSER[USER_NAME()]


This give me the error:

Msg 15198, Level 16, State 1, Procedure sp_helpuser, Line 177
The name supplied (USER_NAME()) is not a user, role, or aliased login.


I am writing a c++ program which will execute the above statement after the user logged on to the database. And, the database user name of some users may not same as their login name.

So, how to execute SP_HELPUSER by passing value returned by USER_NAME() function as argument?

(optional)Is it possible to do this in single line statement?

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-03-25 : 01:30:43
Try this:

Declare @Test sysname
Select @Test = USER_NAME()

Exec SP_HELPUSER @Test

Regards,
Bohra

I am here to learn from Master and help new bees in learning.
Go to Top of Page
   

- Advertisement -