Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
842 views
in Technique[技术] by (71.8m points)

sql server - SQL select print out results of stored procedure

My businesses application supports only reporting with selected data from SQL server.In one business process I have very complicated stored procedure which using others stored procs and it was designed to print out results as log of job done. What I want to catch that print out and select it as varchar(max) so my app can handle that data and display to user.
Here is sample scenario described in TSQL code:

create procedure sp_test_print_out
as
begin
    Print 'Test';
    print 'Test 1';
end
go

create procedure sp_test_print_out_to_select
as 
declare @printOut varchar(max)
set @printOut = exec sp_test_print_out --How I can achieve this ?
select @printOut
end

go

exec sp_test_print_out_to_select
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try setting the values in output parameter

create procedure sp_test_print_out
@printMessages varchar(max) output
as
begin
set @printMessages='Test'
Print 'Test';

set @printMessages= @printMessages + CHAR(10)
set @printMessages= @printMessages + 'Test 1'
print 'Test 1';
end
go


create procedure sp_test_print_out_to_select
as 
begin
declare @printOut varchar(max)
exec sp_test_print_out @printOut output -- can be achieved using output parameter ?
select @printOut
end

go

exec sp_test_print_out_to_select

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...