I have two sp's- main_sp & other_sp. other_sp code is written seperately but it accept 3 parameters supplied from main_sp and it is part of main_sp.
alterprocedure main_spas
declare@returntableastable
(id int, name varchar(100),type varchar(10))
declare@sqlcommand varchar(max),@typevar
varchar(10)
declare db_cursor for
select sqlscript from seltable
open db_cursor for
fetch next from db_cursorinto@sqlcommand
while@@fetch_status=0
begin
insertinto@returntable(id,name)
exec (@sqlcommand)
fetch next from db_cursorinto@sqlcommand
set@typevar=(selectdistinct id from xyz ainner join @returntable b on a.id=b.id)
end
close db_cursor
deallocate db_cursor
exec other_sP (id,name,@typevar)
I am getting this error when I run main_sp
Incorrect syntax error at @typevar
The other_SP
is written is such a way that it accept 3 parameters.Other_SP
is part of main_sp
and I will run only main_sp
from job
In seltable
table - I have two sql queries.
create table seltable (ID, sqlscript)
insert into seltable
select 1,'select id,name from emp'
union
select 2,'select id, name from dept'