May 5, 2006 at 9:30 am
Can somebody tell me what's wrong with the following code, please?
set nocount on
declare @varname varchar(50)
declare @newownername varchar(20)
set @newownername = 'dbo'
declare @import table
(
rownum int identity (1, 1) primary key not null,
tablename nvarchar(255)
)
insert into @import (tablename) values ('chjohnson.christest')
select @varname = tablename from @import
sp_changeobjectowner @varname, @newownername
set nocount off
go
I get the following error.
"Server: Msg 170, Level 15, State 1, Line 12
Line 12: Incorrect syntax near '@varname'."
Any help is appreciated. Thanks.
Chris
May 5, 2006 at 9:36 am
Try this
set nocount on
declare @varname varchar(50)
declare @newownername varchar(20)
set @newownername = 'dbo'
declare @import table
(
rownum int identity (1, 1) primary key not null,
tablename nvarchar(255)
)
insert into @import (tablename) values ('chjohnson.christest')
select @varname = tablename from @import
EXEC sp_changeobjectowner @varname, @newownername
set nocount off
go
May 5, 2006 at 9:45 am
That did it! Thanks a lot, Sriram! I guess the "exec" is needed in a stored procedure, huh?!
May 5, 2006 at 10:54 am
EXEC is short for EXECUTE. That's what causes the stored procedure to run (or be EXECuted).
-SQLBill
May 5, 2006 at 11:40 am
Yeah, I know what "exec" is, but when you run a stored procedure in Query Analyzer, it's optional. I was just commenting on the fact that it is required in stored procedure code. Thanks.
May 7, 2006 at 7:04 pm
Christopher: close interpretation of EXEC, but the requirement to use EXEC/EXECUTE is when there is more than one statement (the procedure call) in a batch. You have to use EXEC in QA when you're calling multiple procedures, performing additional actions, declaring variables, etc.
-Eddie
Eddie Wuerch
MCM: SQL
May 8, 2006 at 8:03 am
Dig it! Thanks all!
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply