Read inside node value of Xml using Sql Server I want to read node values of xml in sql, my xml look like this 



I just want to read value of order node that is 'Order 1'
and my code is

EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
SELECT * FROM OPENXML (@idoc, '/ROOT/Customer/Order',0)
WITH (
    [Order]  varchar(100)
    );
CREATE TABLE test(data xml);
insert into test values
('
&lt;ROOT&gt;
  &lt;Customer&gt;
    &lt;Order&gt;Order 1&lt;/Order&gt;
  &lt;/Customer&gt;
  &lt;Customer&gt;
    &lt;Order&gt;Order 2&lt;/Order&gt;
  &lt;/Customer&gt;
&lt;/ROOT&gt;');
GO



1 rows affected



If you need first &lt;Order&gt; element of your XML data you can use the next sentence.




SELECT data.value('(ROOT/Customer/Order)[1]', 'varchar(100)')
FROM   test;
GO



| (No column name) |
| :--------------- |
| Order 1          |



If you need to select all &lt;Order&gt; elements you can use a CROSS APPLY solution with .nodes()




SELECT T2.lin.value('(Order)[1]', 'varchar(100)')
FROM   test
CROSS APPLY data.nodes('/ROOT/Customer') as T2(lin)
GO



| (No column name) |
| :--------------- |
| Order 1          |
| Order 2          |



dbfiddle here