2021年5月7日星期五

How can I use Database Name for sys databases in queries?

I am using this query where I am getting a list of all extended stored procedure for the Master database.

SELECT p.permission_name, [schema] = SCHEMA_NAME(o.schema_id), object_name = o.name, role_name = u.name  FROM Master.sys.database_permissions p  INNER JOIN master.sys.database_principals u ON p.grantee_principal_id = u.principal_id  INNER JOIN master.sys.all_objects o ON o.object_id = p.major_id  WHERE p.grantee_principal_id = 0 and o.type = 'X' and u.name = 'public'  

Please can someone help me to make the database name use a variable and not hardcoding the name in the query.

Many thanks.

https://stackoverflow.com/questions/67443486/how-can-i-use-database-name-for-sys-databases-in-queries May 08, 2021 at 10:16AM

没有评论:

发表评论