EXECUTE cannot be used as a source when inserting into a table variable. (SQL 2K)

how can exec within exec be done in sql 2000?
LVL 5
25112Asked:
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.

25112Author Commented:
the syntax works in 2005 not 2000
declare @perms table (
ObjectOwner varchar(50) NULL,ObjectName varchar(50) NULL,Grantee varchar(50) NULL,Grantor varchar(50) NULL,ProtectType varchar(50) NULL,[Privilege] varchar(50) NULL,[Column] varchar(10))
declare @DBName sysname
set @DBName = db_name()	

insert @perms
EXEC ('EXEC ' + @DBName + '.dbo.sp_helprotect')

select LTRIM(RTRIM(ProtectType))+' '+LTRIM(RTRIM(Privilege))+' '+' ON '+[ObjectName]+' TO '+Grantee+';
'  from @perms

WHERE ObjectOwner NOT IN('sys','.')  -- excludes sys objects
ORDER BY ProtectType

Open in new window

0
LowfatspreadCommented:
have you tried


EXEC (@DBName + '.dbo.sp_helprotect')

or

EXEC('EXEC ' + @DBName + '.dbo.sp_helprotect')  -- no space between exec and (

?

otherwise use the sp_execsql  stored procedure....
0

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
NOC_TrollCommented:
Another thing to look at is data types.  Looking at the statement you concatenated and passed to the EXEC function:
('EXEC ' + @DBName + '.dbo.sp_helprotect')
It begins with a VARCHAR, followed by data type sysname followed by another VARCHAR.

If you use CAST to change sysname to match the others it should work.

Try
('EXEC ' + CAST(@DBName AS VARCHAR(50)) + '.dbo.sp_helprotect')

Hope this helps.
0
keyuCommented:
no need to write exec command twise

try this

EXEC (CAST(@DBName AS VARCHAR(50))  + '.dbo.sp_helprotect')


or

Declare @str as varchar(250)

Set @str=CAST(@DBName AS VARCHAR(50))  + '.dbo.sp_helprotect'

Exec @str
0
25112Author Commented:
thanks for trying.. but i found that none of the options work with table variable in 2000
0
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
Query Syntax

From novice to tech pro — start learning today.