all groups > sql server (microsoft) > august 2005 >
You're in the

sql server (microsoft)

group:

Getting db User Account



Getting db User Account tabladude NO[at]SPAM gmail.com
8/26/2005 7:57:47 AM
sql server (microsoft): Hi:

Is there some way of accessing the username (SQL Account) that is
running a stored procedure? Basically, in the absence of good row level
security options in this verison of SQL, I want to create a proc like
this:
----------
DECLARE @username

SELECT @username = userfield FROM
PossibleSystemTableWhereCurrentSQLUsernameStored

If @username = 'usera'
BEGIN
SELECT * FROM table1 WHERE conditionfield = 'useravalue'
END

IF @username = 'userb'
BEGIN
SELECT * FROM table1 WHERE conditionfield = 'userbvalue'
END
----------

Is this possible?

Thanks,
Kayda
Re: Getting db User Account xAvailx
8/26/2005 11:28:14 AM
select SUSER_SNAME() should give you the current login.

These articles may be of some help:

By SQL Server MVP Narayana Vyas
http://vyaskn.tripod.com/row_level_security_in_sql_server_databases.htm

SQL Mag (Subscriber only, but you can still download the code)
http://www.windowsitpro.com/SQLServer/Article/ArticleID/42615/42615.html

HTH,

BZ
AddThis Social Bookmark Button