Script all tables permissions

Hello,

I try to script all permissions tables when I run the following query, the result is 4045 rows :
select c.action, o.name, b.name from sys.objects o
INNER JOIN sysprotects c
      ON o.object_id = c.id
INNER JOIN sysusers b
      ON c.uid = b.uid
WHERE o.type IN ('U','P','V')
and b.name = 'F_ADX'
 
ORDER BY o.name

When I try to do the same thing with stored prod and schemaname F_ADX, the result is 0 row

create procedure [dbo].[create_grants]
@Dbname varchar (30),  
@Schsource varchar (30),  
@NewSchema      varchar(30)  
 
AS  
set nocount on
SELECT 'GRANT '+
      CASE c.action
            WHEN 26 THEN 'REFERENCES'
            WHEN 193 THEN 'SELECT'
            WHEN 195 THEN 'INSERT'
            WHEN 196 THEN 'DELETE'
            WHEN 197 THEN 'UPDATE'
            WHEN 198 THEN 'CREATE TABLE'
            WHEN 203 THEN 'CREATE DATABASE'
            WHEN 207 THEN 'CREATE VIEW'
            WHEN 222 THEN 'CREATE PROCEDURE'
            WHEN 224 THEN 'EXECUTE'
            WHEN 233 THEN 'CREATE DEFAULT'
            ELSE 'CREATE RULE'
      END+ ' ON '+ o.name+ ' TO ' + @NewSchema  + CHAR(13) + ';' + CHAR(13)
FROM sys.objects o
INNER JOIN sysprotects c
      ON o.object_id = c.id
INNER JOIN sysusers b
      ON c.uid = b.uid
WHERE o.type IN ('U','P','V')
AND b.name = '@Schsource'
 
ORDER BY o.name

Thanks
Regards
bibi
bibi92Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
AND b.name = '@Schsource'  
 
remove the quotes around @SchemaSource
AND b.name = @Schsource
 


Shannon_LowderCommented:
I tried your query on my server.  It only works if you have some permissions set already.  Try to populate one test user with the permissions you're trying to script.  Then you should get results.

---
Shannon Lowder
Database Engineer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bibi92Author Commented:
Hello,

I execute the script with sysadmin privilege.

Thanks

Regards

bibi
bibi92Author Commented:
Thanks bibi
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.