I'm not good with XML, so is there another way of doing this so if a new hold type is added (like Weekly) I don't have to rewrite my code.
Well Done is better than well said
- Ben Franklin
Code:
datetime smalldatetime,
data1 varchar(10),
amount float
)
set @TotXML='<root>
<BiMonthly datetime="apr 01 2007 00:00" data1="Cash" amount ="5" />
<BiMonthly datetime="apr 01 2007 00:00" data1="Check" amount ="110.14" />
<Monthly datetime="apr 01 2007 00:00" data1="CC" amount ="5000" />
</root>'
exec sp_xml_preparedocument @totInt output, @totXML
insert into #TestTable
select 'BiMonthly' as 'HoldType', * from openxml(@totInt, '/root/BiMonthly',0)
WITH(
datetime smalldatetime,
data1 varchar(10),
amount float)
UNION
select 'Monthly' as 'HoldType', * from openxml(@totInt, '/root/Monthly',0)
WITH(
datetime smalldatetime,
data1 varchar(10),
amount float)
select * from #TestTable
DROP table #TestTable
Well Done is better than well said
- Ben Franklin