Question : SQL Recordset from XML data

I have some xml data that i need to return in a specific format and since I have never really worked with XML I am finding myself at a brick wall.

the code samaple currently reruns the following

Model      Black Flash 1873 Watts 240 VoltsBlack Flash 1973 Watts 220 Volts
Acc.       Black Flash Floor Stand

what i need returned is

Model      Black Flash 1873 Watts 240 Volts
Model      Black Flash 1973 Watts 220 Volts
Acc.        Black Flash Floor Stand

Also the number of options/name can vary and the number of sub item under name can also vary so i need this to be very generic in nature and return in the format shown no matter how many nodes are in the xml
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
SET @XmlData='<options>
				<option>
					<name>Model</name>
						<option_info>
							<item> 
								<itemoption_id>5276</itemoption_id> 
								<itemoption_itemid>4566</itemoption_itemid> 
								<itemoption_weight>0</itemoption_weight> 
								<itemoption_description><![CDATA[Black Flash 1873 Watts 240 Volts]]></itemoption_description> 
								<itemoption_size>16 x 16</itemoption_size> 
								<itemoption_modifyprice>25.00</itemoption_modifyprice> 
								<itemoption_shiprule>1</itemoption_shiprule>
							</item>
							<item> 
								<itemoption_id>5276</itemoption_id> 
								<itemoption_itemid>4566</itemoption_itemid> 
								<itemoption_weight>0</itemoption_weight> 
								<itemoption_description><![CDATA[Black Flash 1973 Watts 220 Volts]]></itemoption_description> 
								<itemoption_size>16 x 16</itemoption_size> 
								<itemoption_modifyprice>25.00</itemoption_modifyprice> 
								<itemoption_shiprule>1</itemoption_shiprule>
							</item>
						</option_info>
					</option>
					<option>
						<name>Acc.</name>
							<option_info>
								<item> 
									<itemoption_id>5561</itemoption_id> 
									<itemoption_itemid>4708</itemoption_itemid> 
									<itemoption_weight>0</itemoption_weight> 
									<itemoption_description><![CDATA[Black Flash Floor Stand]]></itemoption_description> 
									<itemoption_size></itemoption_size> 
									<itemoption_modifyprice>215.00</itemoption_modifyprice> 
									<itemoption_shiprule>1</itemoption_shiprule>
								</item>
							</option_info>
						</option>
					</options>'



select 
R.i.query('name').value('.', 'varchar(30)') [Name], R.i.query('option_info/item/itemoption_description[1]').value('.', 'varchar(100)') [itemoption_description]
FROM @XmlData.nodes('/options/option') R(i)

Answer : SQL Recordset from XML data

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
declare @xmldata xml
SET @XmlData='<options>
				<option>
					<name>Model</name>
						<option_info>
							<item> 
								<itemoption_id>5276</itemoption_id> 
								<itemoption_itemid>4566</itemoption_itemid> 
								<itemoption_weight>0</itemoption_weight> 
								<itemoption_description><![CDATA[Black Flash 1873 Watts 240 Volts]]></itemoption_description> 
								<itemoption_size>16 x 16</itemoption_size> 
								<itemoption_modifyprice>25.00</itemoption_modifyprice> 
								<itemoption_shiprule>1</itemoption_shiprule>
							</item>
							<item> 
								<itemoption_id>5276</itemoption_id> 
								<itemoption_itemid>4566</itemoption_itemid> 
								<itemoption_weight>0</itemoption_weight> 
								<itemoption_description><![CDATA[Black Flash 1973 Watts 220 Volts]]></itemoption_description> 
								<itemoption_size>16 x 16</itemoption_size> 
								<itemoption_modifyprice>25.00</itemoption_modifyprice> 
								<itemoption_shiprule>1</itemoption_shiprule>
							</item>
						</option_info>
					</option>
					<option>
						<name>Acc.</name>
							<option_info>
								<item> 
									<itemoption_id>5561</itemoption_id> 
									<itemoption_itemid>4708</itemoption_itemid> 
									<itemoption_weight>0</itemoption_weight> 
									<itemoption_description><![CDATA[Black Flash Floor Stand]]></itemoption_description> 
									<itemoption_size></itemoption_size> 
									<itemoption_modifyprice>215.00</itemoption_modifyprice> 
									<itemoption_shiprule>1</itemoption_shiprule>
								</item>
							</option_info>
						</option>
					</options>'
select 
R.i.query('../../../name').value('.', 'varchar(30)') [Name],
R.i.value('.', 'varchar(100)') [itemoption_description]
FROM @XmlData.nodes('/options/option/option_info/item/itemoption_description') R(i)
Random Solutions  
 
programming4us programming4us