Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what i have done till now is as :
SQL
ALTER proc [dbo].[WebServiceCall]      
as        
begin        
declare @sUrl varchar(4000),@obj int,@response varchar(800)  
exec sp_OAMethod @obj,'Open',NULL,'GET', @sUrl, false        
exec sp_OAMethod @obj,'send'        
exec sp_OAGetProperty @obj,'responseText', @response OUT        
select  @response [response]        
exec sp_OADestroy @obj         
set @sUrl ='http://10.130.7.147/Eservice/SSISService.asmx/HelloMoon' 
declare @data xml 
declare @data1 xml 
select @data = @response 
declare @str nvarchar(max) 
select @str = cast(@data as Nvarchar(max))
--select @data = @response 
select @str  = replace(@str, '=', '="')
select @str = replace(@str, '|', '" ')
select @str = replace(@str, '^', '"/>'

gettinng response as:
<?xml version="1.0" encoding="utf-8"?>  <string xmlns="http://abc.org/">age=7|Date=15/04/2006^age=5|Date=15/04/2008</string>

How split this into row column format in sql server 2008 using Stored procedure.Thanks..
Posted
Updated 26-Aug-13 1:35am
v3

1 solution

Use this .. it will help...
SQL
DECLARE @str VARCHAR(2000), @strXML VARCHAR(8000),@XML XML
Set @str	= 'age=7|Date=15/04/2006^age=5|Date=15/04/2008'
Set @str	= '<table><row><col>' + @str + '</col></row></table>'
Set @str	= REPLACE(@str,'|','</col><col>')
Set @str	= REPLACE(@str,'^','</col></row> <row><col>')
set @str	= REPLACE(@str,'Date=','')
Set @strXML = REPLACE(@str,'age=','')
Set @XML	= CAST(@strXML AS XML)

--@XML Ouput will be like this:  
--<table>
--  <row>
--    <col>7</col>
--    <col>15/04/2006</col>
--  </row>
--  <row>
--    <col>5</col>
--    <col>15/04/2008</col>
--  </row>
--</table>

SELECT line.col.value('col[1]', 'varchar(1000)') AS Age,
	   line.col.value('col[2]', 'varchar(1000)') AS Date
FROM @XML.nodes('/table/row') AS line(col) 


Output:
SQL
Age	   Date
---      ----------
7	  15/04/2006
5	  15/04/2008

Hope this helps...
 
Share this answer
 
v4
Comments
Aarti Meswania 26-Aug-13 7:50am    
5+:)
Raja Sekhar S 26-Aug-13 7:58am    
Thank you.....
Rambo_Raja 26-Aug-13 8:04am    
well done!great.5*****
Raja Sekhar S 26-Aug-13 8:07am    
Glad to help...

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