Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Does anyone know how to convert the following into a table: <row LocationCode=\"8606\" City=\"Falls City\" State=\"TX\" /> This is results is yielded from executing a stored procedure (EXEC [dbo].[sp_GetSomeData] +@DataID+ FOR XML RAW) and I want to take the results produced and put it into a table like the following,

LocationCode City State
8606 Falls City TX

Can this be done in sql?
Posted
Updated 27-Aug-13 3:15am
v2

Try this...
SQL
Declare @idoc int, @doc varchar(1000) 
Set @doc ='<row LocationCode=\"8606\" City=\"Falls City\" State=\"TX\" />'
Set @doc =Replace(@doc,'\','')  
 -- @doc value will be <row LocationCode="8606" City="Falls City" State="TX" />

EXEC sp_xml_preparedocument @idoc OUTPUT, @doc;
SELECT * FROM OPENXML (@idoc, '/row',1) WITH (LocationCode varchar(10),City varchar(40),State Varchar(40));

Output:
SQL
LocationCode	City	   State
------------  ---------    ------
8606	      Falls City    TX
 
Share this answer
 
v2
Comments
Raja Sekhar S 29-Aug-13 4:00am    
Did it solve the Problem..?

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