Ok, the situation:In the sites we develop we generally have a naming convention and only allow users access to the stored procedures (this is via a web front). As we add new SProcs I want to add the permissions (circa 10 Sprocs at a time) so I wrote/found this code to simplify the process:DECLARE @username varchar(100)SET @username = 'Username'SELECT 'GRANT EXECUTE ON ' + name + ' TO ' + @usernameFROM sysobjectsWHERE xtype = 'p' AND LEFT(name, 4) = 'xyz_'
Which is fine, I was just wondering whether I could completely automate it, I've tried this:DECLARE @username varchar(100), @name varchar(100)SET @username = ''DECLARE cEvent CURSOR FAST_FORWARDFOR SELECT nameFROM sysobjectsWHERE xtype = 'p' AND LEFT(name, 4) = 'xyz_'OPEN cEventFETCH cEvent INTO @name WHILE @@Fetch_Status = 0 BEGIN GRANT EXECUTE ON @name TO @username FETCH cEvent INTO @name ENDCLOSE cEventDEALLOCATE cEvent
But it just complains about @name in GRANT EXECUTE ON @name TO @username.I know I perhaps shouldn't do it like this but is it possible?Thanks,Tim