Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML into SS2005 help

Status
Not open for further replies.

nice95gle

Programmer
Nov 25, 2003
359
US
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.

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top