?
Solved

adding database name in sp_helpuser

Posted on 2010-09-07
5
Medium Priority
?
807 Views
Last Modified: 2012-05-10
is it possible to add the database name in the below code, so i can know which databases have the users with the role backupoperator

thanks
create table #DBO  (GName varchar(80),GID int,User_id_DB varchar(80),uid smallint)
exec sp_msforeachdb 'use [?] insert into #DBO exec sp_helpuser db_backupoperator'  
select * from #DBO where User_id_DB <> 'dbo'
drop table #DBO

Open in new window

0
Comment
Question by:anushahanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 1920 total points
ID: 33619761
create table #DBO  (GName varchar(80),GID int,User_id_DB varchar(80),uid smallint, dbname sysname)
exec sp_msforeachdb 'use [?] insert into #DBO exec sp_helpuser db_backupoperator update #DBO set dbname = ''?'' where dbname is null'  
select * from #DBO where User_id_DB <> 'dbo'
drop table #DBO
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 80 total points
ID: 33619775
db_name() is a function in t-sql that should get current database
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 1920 total points
ID: 33619804
quick fix...make sure you always list the field names


create table #DBO  (GName varchar(80),GID int,User_id_DB varchar(80),uid smallint, dbname sysname)
exec sp_msforeachdb 'use [?] insert into #DBO(gname, gid, user_id, uid) exec sp_helpuser db_backupoperator update #DBO set dbname = ''?'' where dbname is null'  
select * from #DBO where User_id_DB <> 'dbo'
drop table #DBO
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33619991
Thanks Tim.
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33619997
rockiroads, db_name() does not quiet work right inside the sp.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question