how do you assign a variable, then execute it? | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

how do you assign a variable, then execute it?

For example, I would like to assign a "Grant all on table to public". If I assign that as follows, why doesn’t it work? declare @file as varchar(255)
set @file = ‘grant all on categories to public’
@file ?? How do I get it to execute @file?
Thanks to Chappy from the previous post I made. It is ‘exec sp_executesql @file’
]]>