I am trying to query the XML below in a SQL select statement to find the type for book3.
<Book>
<Title>Book1</Title>
<Type>fiction</Type>
<Cost>9.99</Cost>
</Book>
<Book>
<Title>Book2</Title>
<Type>non-fiction</Type>
<Cost>5.99</Cost>
</Book>
<Book>
<Title>Book3</Title>
<Type>fiction</Type>
<Cost>14.99</Cost>
</Book>
<Book>
<Title>Book4</Title>
<Type>non-fiction</Type>
<Cost>19.99</Cost>
</Book>
...
I am trying to select the title "book 3" in my select statement by searching for this as a text, and the type which follows i.e book3,fiction
So far I can perform a select by the index as below but I really want to find the node by incorporating some kind of text='book 3' statement.
SELECT XML.value('(/*//Book/Title/node())[3]', 'nvarchar(max)') as 'result'
I am not familiar on how to do this (I'm quite new to this approach)
Can anyone give me some pointers on how to do this? Or if there are any good resources online I can read up on (I can only find bits on pieces on how to do this in SQL)
Thanks!