XML QUERY LANGUAGES: XQUERY AND XPATH sql:variable The sql:variable function allows you to use any Transact-SQL variable that is in scope at the time the XQuery query is executed. This will be a single value for the entire query, as opposed to the sql:column, where the column value changes with every row of the result. This function is subject to the same data type limitations as sql:column. An example of using sql:variablein an XQuery query would look like this. DECLARE @occupation VARCHAR(50) SET @occupation = is a stooge SELECT xml_col.query( for $b in //person where $b/name= moe return

  • { $b/name/text() } { sql:variable( @occupation ) }
  • ) FROM xml_tab This statement uses the value of a T-SQL variable, @occupation, in the returned sequence in the XQuery query. Multiple Document Query in SQL Server XQuery As we saw in the XQuery specification discussion earlier in this chapter, queries can encompass more than one physical XML document, by using the doc or collection functions. However, in SQL Server s implementation of XQuery, the functions that allow input are not implemented. This is because the XQuery functions are implemented as instance functions that apply to a specific instance of the XML data type. Using the instance functions (xml.query, xml.exist, and xml.value), the XQuery query is single-document-only. So what if you want to combine more than one document, the XQuery equivalent of a SQL JOIN? One way to combine multiple documents to produce a single XQuery sequence as a result is to perform the query over each document separately and concatenate the results. This can be easily accomplished using the SELECT…FOR XML syntax. This may not always be what you want, however. Some multidocument queries are based on using one document to join another in a nested for loop. These types of queries cannot be accomplished by using sequence concatenation. Another way to accomplish multidocument queries is to use the xml.queryfunction on different types, combined with the SQL JOIN syntax. This doesn t deal with the nested tuple problem either. Because .NET stored procedures and UDFs can use most of the .NET APIs, it is possible to use System.Xml.Query (the client-side

    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.