Filtering Values Using sql:limit-field and sql:limit-value
You can limit rows returned from a database query based on some limiting value. These annotations are used to identify the database column that contains the limiting values and to specify a specific limiting value to be used to filter the data returned.
The sql:limit-field annotation is used to identify a column that contains a limiting value. sql:limit-field is used to qualify the join relationship specified using <sql:relationship>. sql:limit-field must be used on an element or attribute that has <sql:relationship> specified.
The sql:limit-value annotation is used to specify the limited value in the column specified in a sql:limit-field annotation. This annotation is optional. If sql:limit-value is not specified, a null value is assumed.
Examples
To create working samples using these examples, you must create the nwind virtual directory (to access the Northwind database) and a virtual name of template type. For more information about creating the nwind virtual directory, see Creating the nwind Virtual Directory.
In creating working samples in each example, templates are used to specify XPath queries against the mapping XDR schema. There are different ways of using annotated XDR schemas in queries, for example, inline schemas and schemas in the URL. For more information, see Using Annotated XDR Schemas in Queries.
A. Limit the customer addresses returned to a specific address type
In this example, a database contains two tables:
- Customer (CustomerID, CompanyName)
- Addresses (CustomerID, AddressType, StreetAddress)
A customer can have a shipping and/or a billing address (the AddressType column values are Shipping and Billing).
This is the mapping schema in which the ShipTo schema attribute maps to StreetAddress column in the Addresses relation. The values returned for this attribute are limited to only Shipping addresses by specifying the sql:limit-field and sql:limit-value annotations. Similarly, the BillTo schema attribute returns only the Billing address of a customer.
This is the schema:
<?xml version="1.0" ?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<ElementType name="Customer" sql:relation="Customer" >
<AttributeType name="CustomerID" />
<AttributeType name="CompanyName" />
<AttributeType name="BillTo" />
<AttributeType name="ShipTo" />
<attribute type="CustomerID" />
<attribute type="CompanyName" />
<attribute type="BillTo"
sql:limit-field="AddressType"
sql:limit-value="billing"
sql:field="StreetAddress"
sql:relation="Addresses" >
<sql:relationship
key="CustomerID"
key-relation="Customer"
foreign-relation="Addresses"
foreign-key="CustomerID" />
</attribute>
<attribute type="ShipTo"
sql:limit-field="AddressType"
sql:limit-value="shipping"
sql:field="StreetAddress"
sql:relation="Addresses" >
<sql:relationship
key="CustomerID"
key-relation="Customer"
foreign-relation="Addresses"
foreign-key="CustomerID" />
</attribute>
</ElementType>
</Schema>
See Also
IIS Virtual Directory Management for SQL Server