--EASY UNDER STANDING FOR XML TO TABLE CONVERSION
DECLARE @XMLSTRING VARCHAR(1000)DECLARE @idoc INT
SET @XMLSTRING='<TABLE><TR><NAME>ARINDAM</NAME><PHONE>9432987305</PHONE><ADDRESS>BARASAT</ADDRESS></TR><TR><NAME>ARINDAM</NAME><PHONE>9432987305</PHONE><ADDRESS>BARASAT</ADDRESS></TR><TR><NAME>RAJA</NAME> <PHONE>9432987306</PHONE> <ADDRESS>KOLKATA</ADDRESS></TR><TR><NAME>BABU</NAME> <PHONE>9831920688</PHONE> <ADDRESS>MADHYAMGRAM</ADDRESS></TR></TABLE>'
--IN THE ABOVE SECTION THIS IS THE XML STRING THAT YOU WANT TO CONVERT INTO TABLEEXEC sp_xml_preparedocument @idoc OUTPUT,@XMLSTRING
SELECT * FROM OPENXML(@idoc,'/TABLE/TR',2)
WITH(NAME VARCHAR(50),PHONE VARCHAR(50),[ADDRESS] VARCHAR(150))
--NOW IF YOU WANT TO USE THIS TABLE INTO YOUR STORED PROCEDURE
--THEN DECLARE A TABLE VARIABLE IN THE FOLLOWING PROCESS
DECLARE @RESULT_TABLE TABLE(NAME VARCHAR(50),PHONE VARCHAR(50),[ADDRESS] VARCHAR(150))
INSERT INTO @RESULT_TABLE(NAME,PHONE,[ADDRESS])
SELECT * FROM OPENXML(@idoc,'/TABLE/TR',2)
WITH(NAME VARCHAR(50),PHONE VARCHAR(50),[ADDRESS] VARCHAR(150))
SELECT * FROM @RESULT_TABLE
Software Download Page
Thanks this is really useful to me
ReplyDelete