USING XQUERY WITH THE XML DATA TYPE The xml.valuefunction is good for mixing data extracted from the XML data type in the same query with columns returned from SQL Server, which, by definition contain a single value. In addition, it can also be used as a predicate in a SQL WHERE clause or a JOIN clause, as in the following query. SELECT the_id FROM xml_tab WHERE xml_col.value( /people[1]/person[1]/@name , VARCHAR(50) ) = curly xml.query(string xquery-text) Although all the functions of the XML data type do invoke the internal XQuery engine, the function that actually executes a complete XQuery query on an instance of the XMLdata type is xml.query. This function takes the XQuery text, which can be as simple or complex as you like, as an input string and returns an instance of the XMLdata type. The result is always an XQuery sequence as the specification indicates, except when your XQuery instance is NULL. If the input instance is NULL, the result is NULL. The resulting instance of the XMLdata type can be returned as a SQL variable, used as input to an INSERT statement that expects an XML type, or returned as an output parameter from a stored procedure. XQuery usually gets its input from the XQuery functions doc() or collection() in dealing with documents from the file system or input from a stream. XQuery can also use a user-defined context document. In SQL Server 2005, though, remember that the xml.query function refers to a specific column (or instance of the XML data type), and input will come from that column or instance s data; this is the context document. The simplest XQuery query might be one that consists only of an XPath 2.0 expression. This would return a sequence containing zero or more nodes or scalar values. Given our previous document, a simple XQuery query like this: SELECT xml_col.query( /people/person ) AS persons FROM xml_tab would return a sequence containing a single node for each row. persons < person name= curly />

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services

Bookmark the permalink.

Comments are closed.