I am trying to return xml that has a specific attribute in sql.
The xml looks like this:
<Settings>
<Item Name="ColorScheme" Type="XDocument">
<ColorScheme>
<ItemStyle Name="element-song" Title="Song" ForeColor="#0538ac" BackColor="#e8f1fa" Media="1" />
<ItemStyle Name="element-song-print" Title="Song (print)" ForeColor="#0538ac" BackColor="" Media="2" />
<ItemStyle Name="element-spot" Title="Spot" ForeColor="#048b27" BackColor="#e9ffee" Media="1" />
<ItemStyle Name="element-spot-print" Title="Spot (print)" ForeColor="#048b27" BackColor="" Media="2" />
<ItemStyle Name="element-programming" Title="Programming" ForeColor="#0538ac" BackColor="#e8f1fa" Media="1" />
<ItemStyle Name="element-programming-print" Title="Programming (print)" ForeColor="#0538ac" BackColor="" Media="2" />
<ItemStyle Name="element-continued-programming" Title="Continued programming" ForeColor="#0538ac" BackColor="#e8f1fa" Media="1" />
<ItemStyle Name="element-continued-programming-print" Title="Continued programming (print)" ForeColor="#0538ac" BackColor="" Media="2" />
</ColorScheme>
</Item>
<Item Name="SendWeeklyNewAccountEmail" Type="Boolean">False</Item>
<Item Name="UseEstimatedDurationsForAnalysis" Type="Boolean">True</Item>
<Item Name="CalendarStyle" Type="Int32">1</Item>
<Item Name="IncludeAdExForAnalysis" Type="Boolean">True</Item>
</Settings>
the query I use to select these fields that contain the colorscheme attribute are:
SELECT * FROM CustomSettings WITH (NOLOCK)WHERE settings_xml.value('(/Settings/Item/@Name)[1]', 'varchar(25)') = 'ColorScheme' order by 1 desc
The problem I am running into is it only selects the xml that has ColorScheme as the first field. If its located further in the xml (which is a possibility) it doesnt get selected. I understand this is due to me having [1] in my query, but the query is not correcct if I remove this portion. So what do I put in its place to make it not position specific?
1 Answer