Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi everyone i wanna specially DENY, GRANT tables for some user there is a code which i tried to run.there is a mistake Line 14: Incorrect syntax near '@name'.please help me. thank youdeclare @name varchar(30)DECLARE c1 CURSOR FORSelect name From sysobjects WHERE xtype in ('U','P','FN','V') order by nameOPEN c1FETCH NEXT FROM c1 INTO @nameWHILE @@FETCH_STATUS=0BEGINGRANT SELECT, INSERT, DELETE ON @name TO ARGEMASFETCH NEXT FROM c1 INTO @nameENDCLOSE c1DEALLOCATE c1
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-12-04 : 10:56:24
Declare a variable up top like this:
DECLARE @sql NVARCHAR(4000);
Then change the code between begin and end to this:
BEGIN SET @sql = 'GRANT SELECT, INSERT, DELETE ON ' + @name + ' TO ARGEMAS' EXEC (@sql); FETCH NEXT FROM c1 INTO @nameEND