Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 get returned from stored procedure

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-02-08 : 02:35:40
the following:
exec dbo.usp_httppost 'http://www.xxx.com/gettails.asp','reg=ABC123'

returns a recordset (with one record) one of the fields being http_responsetext

now in another stored procedure
I want to select @details=
calling that stored procedure with reg being by @reg and rturning the http_responsetext

how do i do this?

Kristen
Test

22859 Posts

Posted - 2010-02-08 : 03:36:09
Also return http_responsetext (from usp_httppost) in an OUTPUT variable?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-08 : 04:35:59
see this

http://www.sqlteam.com/article/stored-procedures-returning-data
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-02-08 : 08:06:41
thanks but i still seem to be doing something wrong

this is my sp which executes but i get an error when running


alter PROCEDURE spgetdetails
-- Add the parameters for the stored procedure here
@reg nvarchar(50)
AS
declare @cardetails nvarchar(200),
@http_responsetext nvarchar(200)

BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
EXEC dbo.usp_httppost @url='http://www.ccc.com/getcardetails.asp',

@post =@reg,
@http_responsetext = @http_responsetext OUTPUT



END
GO

when i run this i get an error
@http_responsetext is not a parameter for procedure usp_httppost

any ideas what i'm doing wrong?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-08 : 08:28:57
is there a parameter @http_responsetext defined for dbo.usp_httppost as well?
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-02-08 : 08:37:40
no the usp_httpost returns http_responsetet a recordset field - how do I access that?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-08 : 08:47:04
quote:
Originally posted by esthera

no the usp_httpost returns http_responsetet a recordset field - how do I access that?



you cant acces that through a variable unless you define one inside procedure and return data through it (refer link posted earlier)
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-02-08 : 13:36:51
ok so i changed taht
but now when i run this stored procedure i get the recordset that's returned from the orginal stored procedure
but i just want the field of httppost_recordset

doing

@http_responsetext = @http_responsetext OUTPUT
select @http_responsetext as cardetails
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-08 : 13:41:38
quote:
Originally posted by esthera

ok so i changed taht
but now when i run this stored procedure i get the recordset that's returned from the orginal stored procedure
but i just want the field of httppost_recordset

doing

@http_responsetext = @http_responsetext OUTPUT
select @http_responsetext as cardetails


can you show your current procedure code?
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-02-09 : 01:17:55
procedure is



create procedure [dbo].[usp_httppost2]
(
@URL varchar(512),
@post varchar(4000),
@WebLogin varchar(128) = null,
@WebPassword varchar(128) = null,
@ProxyLogin varchar(128) = null,
@ProxyPassword varchar(128) = null,
@http_responsetext nvarchar(250) OUTPUT

)
/*
returns @usp_httppost table
(
return_status bit null, -- 0 is OK, 1 is error
error_msg varchar(4096) null,
HTTP_Status varchar(30) null,
HTTP_AllResponseHeaders text null,
HTTP_ResponseText text null
)
*/
as
begin
/*******************************************************************
Name : usp_httppost
Server : SQLserver 2000
Description : Post data as coming from an HTML FORM with METHOD=POST
to an URL and retrieve the result.
Parameters : @URL : the url to use ( like https://www.d-trix.com )
@post : the parameters to post
@WebLogin : (optional) The Username for the webserver
@WebPassword : (optional) The password for the webserver
@ProxyLogin : (optional) The Username for the proxyserver
@ProxyPassword : (optional) The password for the proxyserver
Notes : . The data to be posted should be like ?param1=val1&par2=val2
. if a table called #usp_httppost exists, the result is stored
into that table. If not, the procedure returns a resultset.
Date : 2005-01-19
Author : Bert De Haes ( bertdehaes@scarlet.be )
History :
*******************************************************************/

set nocount on

declare @http int, -- the objecttoken for WinHttp.WinHttpRequest.5.1
@rc int, -- the return code from sp_OA procedures
@src varchar(255), -- the source of an error
@desc varchar(512), -- the desciption of an error
@Doing varchar(512), -- What are we doing when calling a sp_OA proc
@TableExisted bit -- Did the temp table exists yes(1) or no(0)

-- init

set @rc = 0

if object_id('tempdb..#usp_httppost') is null
begin
-- The temp table #usp_httppost does not exists
set @TableExisted = 0
create table #usp_httppost
(
return_status bit null, -- 0 is OK, 1 is error
error_msg varchar(4096) null,
HTTP_Status varchar(30) null,
HTTP_AllResponseHeaders text null,
HTTP_ResponseText text null
)
end
else
begin
set @TableExisted = 1
truncate table #usp_httppost
end

-- Insert a default record

insert #usp_httppost ( return_status, error_msg )
values ( 1 , 'Unknown error' )

-- create a table to store output from different sp_OA calls

create table #tempresult
(
HTTP_Status varchar(30) null,
HTTP_AllResponseHeaders text null,
HTTP_ResponseText text null
)

-- create the 'WinHttp.WinHttpRequest.5.1' object

set @Doing = 'Create WinHttp.WinHttpRequest.5.1 object.'
exec @rc = master.dbo.sp_OACreate 'WinHttp.WinHttpRequest.5.1', @http output
if @rc <> 0 goto Error


-- open the url on the server

set @Doing = 'Open("POST" , "' + @URL + '", 0 )'
exec @rc = master.dbo.sp_OAMethod @http, @Doing
if @rc <> 0 goto Error

-- set the SetRequestHeader

set @Doing = 'SetRequestHeader("Content-Type","application/x-www-form-urlencoded")'
exec @rc = master.dbo.sp_OAMethod @http,@Doing
if @rc <> 0 goto Error

if @WebLogin is not null AND @WebPassword is not null
begin
-- Set the Credentials for the Webserver

set @Doing = 'SetCredentials("' + @WebLogin + '","' + @WebPassword + '",0)'
exec @rc = master.dbo.sp_OAMethod @http, @Doing
if @rc <> 0 goto Error
end

if @ProxyLogin is not null AND @ProxyPassword is not null
begin
-- Set the Credentials for the Proxy

set @Doing = 'SetCredentials("' + @ProxyLogin + '","' + @ProxyPassword + '",1)'
exec @rc = master.dbo.sp_OAMethod @http, @Doing
if @rc <> 0 goto Error
end

-- send the info

set @Doing = 'Send("' + @post + '")'
exec @rc = master.dbo.sp_OAMethod @http,@Doing
if @rc <> 0 goto Error

-- Get the HTTP_Status

set @Doing = 'Status'
truncate table #tempresult
insert #tempresult (HTTP_Status)
exec @rc = sp_OAMethod @http,@Doing
if @rc <> 0 goto Error

update #usp_httppost
set HTTP_Status = #tempresult.HTTP_Status
from #tempresult
where #tempresult.HTTP_Status is not null

-- Get the ResponseHeaders

set @Doing = 'GetAllResponseHeaders'
truncate table #tempresult
insert #tempresult (HTTP_AllResponseHeaders)
exec @rc = sp_OAMethod @http,@Doing
if @rc <> 0 goto Error

update #usp_httppost
set HTTP_AllResponseHeaders = #tempresult.HTTP_AllResponseHeaders
from #tempresult
where #tempresult.HTTP_AllResponseHeaders is not null

-- retrieve the ResponseText

set @Doing = 'ResponseText'
truncate table #tempresult
insert #tempresult (HTTP_ResponseText)
exec @rc = sp_OAMethod @http,@Doing
if @rc <> 0 goto Error

update #usp_httppost
set HTTP_ResponseText = #tempresult.HTTP_ResponseText
from #tempresult
where #tempresult.HTTP_ResponseText is not null

-- Everything went well

update #usp_httppost
set return_status = 0,error_msg = 'DONE'

-- if we get here the normal way, don't do error
GOTO Cleanup

Error:

-- Get error information

if @http is not null
begin
exec sp_OAGetErrorInfo @http, @src OUT, @desc OUT
end
else
begin
set @src = '?'
set @desc = '?'
end

update #usp_httppost
set return_status = 1,
error_msg =
'Error [' + ISNULL( master.dbo.fn_hexadecimal(@rc) ,'' ) +
'], While [' + ISNULL( @Doing , '' ) +
'], Source [' + ISNULL( @src , '' ) +
'], Description [' + ISNULL( @desc , '' ) + ']'

-- Destroy created object(s)

Cleanup:
if @http is not null
begin
exec @rc = master.dbo.sp_OADestroy @http
set @http = null
if @rc <> 0 goto Error
end

-- Give the result back to the caller

Result:
if @TableExisted = 0
select * from #usp_httppost

return 0
end
select @http_responsetext= http_responsetext from #usp_httppost
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-09 : 08:47:30
[code]
create procedure [dbo].[usp_httppost2]
(
@URL varchar(512),
@post varchar(4000),
@WebLogin varchar(128) = null,
@WebPassword varchar(128) = null,
@ProxyLogin varchar(128) = null,
@ProxyPassword varchar(128) = null,
@http_responsetext nvarchar(250) =NULL OUTPUT

)
...

-- Give the result back to the caller

Result:
if @TableExisted = 0
select * from #usp_httppost

return 0
end
-- Give the result back to the caller

Result:
if @TableExisted = 0
select TOP 1 @http_responsetext= http_responsetext from #usp_httppost
select * from #usp_httppost

return 0
end
select @http_responsetext= http_responsetext from #usp_httppost
[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-09 : 08:56:17
Kristen why did you remove last part? how else would output variable get value from table?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-09 : 09:23:08
Removed it because it was after the RETURN (and, I think, outside the final END

(But I made a formatting error in my original, and did strikethrough for half my answer, by mistake, which may be what you saw?)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-09 : 09:25:04
quote:
Originally posted by Kristen

Removed it because it was after the RETURN (and, I think, outside the final END

(But I made a formatting error in my original, and did strikethrough for half my answer, by mistake, which may be what you saw?)


oh ok
I see now
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-02-09 : 09:46:49
thanks i got it :)
Go to Top of Page
   

- Advertisement -