Tuesday 15 March 2011

sql server - Selecting a value from XML data type -


How to write a SQL Server query that selects from an XML data type and selects the attribute in an element Which corresponds on the basis of other attributes.

Imagine the following example:

  Create table debuts. Configuration (Configuration xml not blank); Insert in the DOO. Configuration (configuration) value (convert (XML, ''  Threshold automation announcements NoofRequests = "25" />   & lt; ; / DoSRequestAnalysis & gt; & lt; / Configuration & gt; ')); Config.value ('(/ / configuration / DoSRequestAnalysis / Windows / window [@ name = "shortest"] / duration) [0]', 'Small' Select from dbo.configuration; - I value the characteristic period I want to select, that is 15, but this return empty   

how to write a question, so does it choose the duration attribute?

Many thanks

You are close, just change [0] to [1]

  Select configuration.value ('(/ / configuration / DoSRequestAnalyst / windows / window [@ name = "smallest"] / duration) [1]', 'smallint')    

No comments:

Post a Comment