Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Read XML with Stored procedures?
Message
 
 
À
05/03/2003 07:57:10
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
00761414
Message ID:
00761422
Vues:
23
>Hi,
>
>Is there a way in which I can read an XML file into a table using a stored procedure?
>
>Thank You,
>
Hi Alvin,

Here's a sample code that reads XML. See BOL for details.
DECLARE @hDoc int, @xml nvarchar(4000)
SET @Xml = 
	'<ROOT>
	<crstemp product_id="1" unit_cost="16.3800" unit_price="18.0000"/>
	<crstemp product_id="2" unit_cost="17.2900" unit_price="19.0000"/>
	<crstemp product_id="3" unit_cost="9.1000" unit_price="10.0000"/>
	<crstemp product_id="4" unit_cost="20.0200" unit_price="22.0000"/>
	<crstemp product_id="5" unit_cost="19.4285" unit_price="21.3500"/>
	</ROOT>'
	
EXECUTE sp_xml_preparedocument @hDoc OUTPUT, @xml

SELECT * FROM OPENXML(@hDoc, '/ROOT/crstemp',1)
  WITH (product_id char(6),
		unit_cost numeric(9,4),
		unit_price numeric(9,4))

EXECUTE sp_xml_removedocument @hDoc
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform