Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

pass dynamic sql values to other stored procedure

$
0
0

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@ReturnTable astable
(RowId int identity(1,1)primarykey, id int, name varchar(100),type varchar(10));

declare@sqlcommand varchar(max),@typevar varchar(10),@Name varchar(100),@id int,@Loop int,@TotalRows int;


select@Loop =0,@TotalRows =0;
declare db_cursor for
select sqlscript from dbo.seltable

open db_cursor

fetch next from db_cursorintointo@sqlcommand

while@@fetch_status=0
begin

insertinto@returntable(id,name)

exec(@sqlcommand)
set@TotalRows =@TotalRows +@@ROWCOUNT;

fetch next from db_cursor into@sqlcommand


end
close db_cursor
deallocate db_cursor


while@Loop <=@TotalRows
BEGIN
set@Loop  =@Loop +1;
selectdistinct@typevar=a.Type
  from xyz a innerjoin@returntable b on a.id=b.id
where b.RowID =@Loop;
;
executeother_sP@id=@id,@name=@name,@typevar=@typevar

end

My other stored procedure is like this...The issue here it is inserting field names in datatable instead of values from main_sp

alter procedure other_sp ( @id int,@name varchar(10),@type varchar(10)) as

begin

insert into datatable(id,name,type)

values (@id,@name,@typevar)

end


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>