Click here to Skip to main content
15,910,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
CREATE PROC [dbo].[UPLOAD]

@WarrantyCode AS NVARCHAR(20),
	@Serial AS NVARCHAR(50) ,
	@ProductTitle AS NVARCHAR(50) ,
	@ShopCenter AS NVARCHAR(70) ,
	@AddDate DATE ,
	@Bill AS NVARCHAR(50) 

AS
 

DECLARE @url as nvarchar(256)
Declare @Obj as Int;
Declare @Response as Varchar(8000);
DECLARE @hr AS INT
DECLARE @src AS VARCHAR(MAX)
DECLARE @desc AS VARCHAR(MAX)


 SET @url = 'http://MY IP:9671/MyWebService.asmx/Upload?WarrantyCode=' + @WarrantyCode + '&Serial=' + @Serial + '&ProductTitle=' + @ProductTitle + '&ShopCenter=' + @ShopCenter + '&AddDate=' + CAST(@AddDate AS NVARCHAR(20)) + '&Bill=' + @Bill
	Exec @hr=sp_OACreate 'MSXML2.XMLHTTP', @Obj OUT
	EXEC sp_OACreate 'MSXML2.ServerXMLHttp.3.0', @obj OUT
    EXEC sp_OAMethod @obj, 'open', NULL, 'POST', @url, false
    EXEC sp_OAMethod @obj, 'send'
    EXEC sp_OAGetProperty @obj, 'ResponseText', @Response OUTPUT 
    SELECT @url AS URL, @Response AS [response], CHARINDEX('amiressami.com', @Response) AS IsOK, CHARINDEX('Roozbeh', @Response) AS Result
    EXEC sp_OADestroy @obj

RETURN




I have this SP
I need to read this parameter (response, IsOK, Result) after execute SP how can I do that???

Posted

1 solution

1. Declare the variables as out parameters to the SP
2. When calling stored procedure, declare a variable for each of the out parameters and pass them to the stored procedure:
SQL
CREATE PROC [dbo].[UPLOAD]
 
@WarrantyCode AS NVARCHAR(20),
	@Serial AS NVARCHAR(50) ,
	@ProductTitle AS NVARCHAR(50) ,
	@ShopCenter AS NVARCHAR(70) ,
	@AddDate DATE ,
	@Bill AS NVARCHAR(50) ,
        @Response as Varchar(8000) output
 
AS
 
 
DECLARE @url as nvarchar(256)
Declare @Obj as Int;
--Declare @Response as Varchar(8000);
DECLARE @hr AS INT
DECLARE @src AS VARCHAR(MAX)
DECLARE @desc AS VARCHAR(MAX)
 

 SET @url = 'http://MY IP:9671/MyWebService.asmx/Upload?WarrantyCode=' + @WarrantyCode + '&Serial=' + @Serial + '&ProductTitle=' + @ProductTitle + '&ShopCenter=' + @ShopCenter + '&AddDate=' + CAST(@AddDate AS NVARCHAR(20)) + '&Bill=' + @Bill
	Exec @hr=sp_OACreate 'MSXML2.XMLHTTP', @Obj OUT
	EXEC sp_OACreate 'MSXML2.ServerXMLHttp.3.0', @obj OUT
    EXEC sp_OAMethod @obj, 'open', NULL, 'POST', @url, false
    EXEC sp_OAMethod @obj, 'send'
    EXEC sp_OAGetProperty @obj, 'ResponseText', @Response OUTPUT 
    SELECT @url AS URL, @Response AS [response], CHARINDEX('amiressami.com', @Response) AS IsOK, CHARINDEX('Roozbeh', @Response) AS Result
    EXEC sp_OADestroy @obj
 
RETURN

Call like this:
SQL
declare @response varchar(8000)
exec dbo.UPLOAD .........., @response output

Now, your response variable will contain the value assigned to it in the SP. I only changed @response, you need to do the others as well.

Looking at your SP, that's actually exactly the same thing you are already doing when calling sp_OAGetProperty, so reading your own SP you could have already found out the answer yourself.
 
Share this answer
 
v2
Comments
Roozbeh Amiressami 7-Sep-14 1:05am    
Declare @response varchar(8000)
EXEC UPLOAD @wc, @Se, @PT, @SC, @AD, @Bi, @response output
SELECT @response;



Msg 8144, Level 16, State 2, Procedure UPLOAD, Line 0
Procedure or function UPLOAD has too many arguments specified.
kbrandwijk 8-Sep-14 10:44am    
Did you update your SP definition to include the new @response parameter?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900