开发者

Adding Result Sets into One

开发者 https://www.devze.com 2023-04-11 10:11 出处:网络
I have a stored Procedure (Generate_Insert)which will output an Insert statement as output given a table name.

I have a stored Procedure (Generate_Insert)which will output an Insert statement as output given a table name.

But Now I have created another procedure which looks like:

开发者_如何转开发
Create Procedure Inserts
As
Begin

EXEC Generate_Insert @Table = 'Admin'

EXEC Generate_Insert @Table = 'Impas'

EXEC Generate_Insert @Table = 'Asui'

EXEC Generate_Insert @Table = 'Alstd'

END

The sample output of

EXEC Generate_Insert @Table = 'Admin' is:

Insert into Admin(Ad_ID,Name,Desc) Values (1,'John','Employee')

The problem is when I execute this procedure I am getting result sets in different windows but i want the output as one result set.

How can I do this?


Assuming the output of Generate_Insert is a varchar(max)

you can do this inside Inserts:

create table #temp
(
insert_stmt varchar(max)
)

insert into #temp 
EXEC Generate_Insert @Table = 'Admin'
insert into #temp 
EXEC Generate_Insert @Table = 'Impas'
insert into #temp 
EXEC Generate_Insert @Table = 'Asui'
insert into #temp 
EXEC Generate_Insert @Table = 'Alstd'

select * from #temp
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号