USING XQUERY WITH THE XML DATA TYPE two

USING XQUERY WITH THE XML DATA TYPE two extension functions for exactly this purpose: sql:column and sql: variable. These keywords allow you to refer to relational columns in tables and Transact-SQL variables, respectively, from inside an XQuery query. These functions can be used anywhere an XQuery query can be used, namely xml.exist, xml.value, xml.query, and xml.modify; xml.modify is discussed in the next section. The functions cannot be used to assign a value to SQL data; that means that they cannot be used on the left-hand side of an assignment statement in XQuery, as in let sql:column := somevalue . The functions can refer to any SQL data type with the following exceptions: The XMLdata type User-defined data types TIMESTAMP UNIQUEIDENTIFIER TEXTand NTEXT IMAGE sql:column This function refers to a column in the current row of the current SQL query. The column can be in the same table as the XMLdata type column, or it can be included in the result as part of a join. The table must be in the same database and owned by the same schema owner, and is specified using a two-part name in the format Tablename.Columnname (without the quotes). Here s an example, using the table with name as a subelement that we ve been using in the XQuery xml.nodesexamples. SELECT xml_col.query( for $b in //person where $b/name= moe return

  • { $b/name/text() } in record number {sql:column( xml_tab.the_id )}
  • ) FROM xml_tab This returns the following result (note: the first two rows in the result are empty).

  • moe in record number 3
  • moe in record number 4
  • Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

    Bookmark the permalink.

    Comments are closed.