Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sql 2000 OPENXML to insert

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2007-02-23 : 04:49:49
Hi,
Trying to use OpenXML in sql server 2000 to insert the xml data into table.
As you can see in the sql code I am first trying to see if the select * works but nothing is returned. The idea is to eventually get this to do the insert into the table.
can you please see what i am doing wrong?
Here is the xml sample. Next you will see the SQL
Thanks

declare @doc varchar (1000)
declare @idoc int


SET @doc = '
<marketData>
<date>21-Feb-2007 11:26:39</date>
<producedBy>Dominic Harris</producedBy>
<isDifferential>True</isDifferential>
<forwardCurves>
<forwardCurve code="CU LME_FUT">
<maturities>
<maturity>
<contractMonth />
<date>30-Dec-1899</date>
<mid>-2,400.00</mid>
<bizDays>0</bizDays>
</maturity>
<maturity>
<contractMonth />
<date>30-Dec-1899</date>
<mid>-2,382.00</mid>
<bizDays>0</bizDays>
</maturity>
<maturity>
<contractMonth />
<date>30-Dec-1899</date>
<mid>-2,388.00</mid>
<bizDays>0</bizDays>
</maturity>
<maturity>
<contractMonth />
<date>30-Dec-1899</date>
<mid>-2,394.00</mid>
<bizDays>0</bizDays>
</maturity>
</maturities>
</forwardCurve>
</forwardCurves>
</marketData>
'


--Create an internal representation of the XML document
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc

--insert into tblMarketValues
select *
FROM OPENXML (@idoc, '/marketData/forwardCurves/forwardCurve/maturities/maturity',2)
WITH (
contractMonth varchar(80),
[date] datetime,
mid decimal(10, 5),
bizDays int
)

-- Clear the XML document from memory
EXEC sp_xml_removedocument @idoc
   

- Advertisement -