Tuesday, March 27, 2012

GRANTING a variable

When exec.
GRANT SELECT ON @.variable_name to user_name
The above does not work due to the variable.
Is there no way of dynamically assigning the table-name?
Thks again.You have to create the complete statement as a string ad then execute it
with EXEC or sp_xecutesql. Read an excellent article at
http://www.algonet.se/~sommar/dynamic_sql.html.
Dejan Sarka, SQL Server MVP
Associate Mentor
Solid Quality Learning
More than just Training
www.SolidQualityLearning.com
"Wayne" <anonymous@.discussions.microsoft.com> wrote in message
news:11f301c3fb91$454511d0$a401280a@.phx.gbl...
> When exec.
> GRANT SELECT ON @.variable_name to user_name
> The above does not work due to the variable.
> Is there no way of dynamically assigning the table-name?
> Thks again.|||Hi,
Yes you can do it, Look in to the below code
declare @.sql nvarchar(200)
declare @.tbl_name varchar(30)
set @.tbl_name='sysobjects'
set @.sql = 'grant select on '+ @.tbl_name + ' to public'
exec sp_executesql @.sql
Thanks
Hari
MCDBA
"Wayne" <anonymous@.discussions.microsoft.com> wrote in message
news:11f301c3fb91$454511d0$a401280a@.phx.gbl...
> When exec.
> GRANT SELECT ON @.variable_name to user_name
> The above does not work due to the variable.
> Is there no way of dynamically assigning the table-name?
> Thks again.sql

No comments:

Post a Comment