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.
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.