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

using sp_helprolemember to determine user role

Status
Not open for further replies.

tklear

Programmer
Jan 16, 2003
37
0
0
US
I need to be able to tell if the system_user is a member of a certain role (db_owner). So I set up a stored procedure that returns me a boolean indicating if he is in the role:

CREATE Procedure roleGrabber
@systemUser varchar(200), @roleName varchar(200), @isMember bit out
as

SET @isMember = 0

DECLARE @returnCode bit
CREATE table #tempRoles(
dbRole varchar(200)
,memberName varchar(2000)
,memberSID varchar(2000)
)
insert into #tempRoles execute @returnCode = sp_helprolemember @roleName

select distinct @isMember = 1 from #tempRoles where memberName = @systemUser

DROP TABLE #tempRoles
GO

I call it from my stored procedure:
DECLARE @isMember bit
DECLARE @userName varchar(200)
DECLARE @returnCode bit

SET @userName = system_user
exec @returnCode = roleGrabber @userName, db_owner, @isMember OUTPUT

This all seems to work, but the problem is it returns an extra recordset for the records inserted into the temporary table in roleGrabber. How can I suppress that - I have a generic ASP page that handles all my stored procedures of a certain type and it is expecting the data records first.

I tried a user defined function but they don't allow temp tables. Then I tried function that returns a table variable but it didn't allow me to use EXECUTE when inserting into a table variable.

Can anyone help? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top