Hi,
I know how to select using openxml.
Could you please let me have a sample code on how to delete records from a table based on what is inside an xml.
Thanks
Something like:
delete from table1
where
OPENXML (@.idoc, '/marketData/forwardCurves/forwardCurve/maturities/maturity',2)
WITH (
contractMonth varchar(50),
[date] datetime,
mid varchar(50),
bizDays int
)
There are a couple of ways to approach this. One of the easiest ways (again easy but not necessarily the highest performance) is to use a JOIN.
Example :
delete from table1 FROM table1 JOIN
SELECT contractMonth, [date], mid, bizdays
OPENXML (@.idoc, '/marketData/forwardCurves/forwardCurve/maturities/maturity',2)
WITH (
contractMonth varchar(50),
[date] datetime,
mid varchar(50),
bizDays int
)) example1 on table1."commonkey" = example1."commonkey"
You can use OPENXML in FROM clause so do below:
delete from table1
where exists (
select *
from OPENXML(...)
with (...) as x
where x.contractMonth = table1.contractMonth
and x.[date] = table.[date]
...
)
No comments:
Post a Comment