Friday, February 10, 2017

Create a data source query

Create a data source query

You can add, remove, or arrange fields and also filter or sort data by applying a query to the data source. Query options are available only for SQL-based data sources, including Microsoft SharePoint lists and libraries, individual databases (the Database Connections section of the Data Source Library task pane), and linked databases (database connections included in the Linked Sources section of the Data Source Library task pane).

Field selection, filtering, and sorting at the source level aren't available for XML files, server-side scripts, or XML Web services, because these data sources don't have a query language like SQL. Instead, field selection, filtering, and sorting for these data sources are performed when you create the Data View that displays the data.

If you want to modify the fields that are included for default SharePoint lists or libraries in the Data Source Library, or if you want to link lists or libraries to other data sources, you first need to create a copy of the data source connection for that list or library and then modify it.

In this article

Unique query options for different types of data sources

Add, remove, or arrange fields

Add, delete, or modify a filter

Add or remove a sort order

Unique query options for different types of data sources

In addition to offering the ability to pick fields, apply filters, and sort data in a data source, each of the data source types provides additional options for specifying a query.

SharePoint lists and libraries

When you specify a query for SharePoint lists and libraries, you can also specify the scope of the query by using the options in the Item and folder scope list.

Item and folder scope options

The Item and folder scope options specify whether the current query spans folders and subfolders. This is particularly useful when you are working with SharePoint libraries. For example, if the Shared Documents folder contains not only files but also subfolders that also contain files, you can specify which files or folders or both should be included in the query. The options are as follows:

  • To apply the query to all of the files and all of the subfolders in the current folder, click Default.

  • To apply the query only to the files in the current folder and not to any of the subfolders, click FilesOnly.

  • To apply the query to all of the files in all of the folders and not to any of the subfolders in the entire site, click Recursive.

  • To apply the query to all of the files in all of the folders and all of the subfolders in the entire site, click RecursiveAll.

Database connections

When you specify an SQL query for database connections, you can also specify whether the read and write statements are synchronized when the query is modified.

Automatically generate write statements
The option to generate SQL write statements for database connections is selected by default. This option synchronizes new write statements in addition to read statements whenever a database connection query is modified.

A read statement is an SQL statement that retrieves and displays data that cannot be modified. A write statement is an SQL statement that retrieves data that can be modified and then saved to the original data source. If you are automatically generating write statements, you already have the statements generated in case you ever want to create a data form. For more information about creating a data form, see Insert a Data View as a form.

Linked data sources

As noted earlier, you can modify a query for a linked data source only if the linked data source comprises two database connections that are joined rather than merged. Also, when you are working with linked database connections, you have the option of outputting the data in tabular form or in hierarchical form.

Modify a query for linked databases in the Data Source Library

Tabular is the best option when you are working with two linked databases that have a one-to-one relationship (that is, one record in either database is related to exactly one other record in the other database).

Hierarchical may be the better option if you have linked databases that have a one-to-many relationship (that is, one record in one database is related to multiple records in other databases).

Top of Page

Add, remove, or arrange fields

You can add, remove, or arrange fields in the data source. When you do so, you are only changing which fields are available for viewing in the Data View Details task pane. You are not adding, removing, or arranging fields in the actual data.

  1. On the Task Panes menu, click Data Source Library.

  2. In the Data Source Library task pane, click the data source that you want, and then click Properties.

  3. On the Source tab of the Data Source Properties dialog box, under Query, click Fields.

    Note: The options under Query are available only for the following SQL data sources: SharePoint lists and libraries, databases, and linked data sources that comprise two database tables in the same database. Also, if the data source uses a custom query, you see the Edit Custom Query button instead of options for Fields, Filter, and Sort. To delete a custom query, click Configure Database Connection, click Next, and then click Finish. In the Edit Custom SQL Commands dialog box, for each tab that displays an SQL statement, click Edit Command, and then delete the SQL statement.

    The Query section in the Daa Source Properties dialog box for a SharePoint list or library

    The Query section on the Source tab in the Data Source Properties dialog box.

  4. In the Displayed Fields dialog box, do any of the following:

    • To add a field to the data source, under Available fields, click the field that you want, and then click Add.

    • To remove a field from the data source, under Displayed fields, click the field that you want, and then click Remove.

    • To change the order of the fields in the data source, under Displayed fields, click the field that you want to move, and then click either Move Up or Move Down.

      Note: Moving a field up in the list moves the column to the left in the data table. Moving a field down in the list moves the column to the right.

      Tip: To select multiple fields at the same time, hold down CTRL while you click each of the fields.

Top of Page

Add, delete, or modify a filter

You can filter data by creating a filter query. When you filter a data source, you apply a filter so that the data source displays only data that satisfies the criteria that you specify. For example, you may have a data source that includes hundreds or thousands of records. However, you want to view only a subset of those records. You can create a filter so that only that subset of records is displayed in your data source.

  1. On the Task Panes menu, click Data Source Library.

  2. In the Data Source Library task pane, click the data source that you want, and then click Properties.

  3. On the Source tab of the Data Source Properties dialog box, under Query, click Filter.

    Note: The options under Query are available only for the following SQL data sources: SharePoint lists and libraries, databases, and linked data sources that comprise two database tables in the same database. Also, if the data source uses a custom query, you see the Edit Custom Query button instead of options for Fields, Filter, and Sort. To delete a custom query, click Configure Database Connection, click Next, and then click Finish. In the Edit Custom SQL Commands dialog box, for each tab that displays an SQL statement, click Edit Command, and then delete the SQL statement.

    The Query section in the Daa Source Properties dialog box for a SharePoint list or library

    The Query section on the Source tab in the Data Source Properties dialog box.

  4. In the Data Source Properties dialog box, click Filter. The Filter Criteria dialog box appears.

You are now ready to add, delete, or modify a filter.

Add a filter

Delete a filter

Modify a filter

Add a clause to an existing filter

Group the clauses in a filter

Modify a clause

Delete a clause

Add a filter

  1. In the Filter Criteria dialog box, click Click here to add a new clause.

  2. Click the Field Name box, and then click the field that contains the values that you want.

  3. Click the Comparison box, and then click the operator that you want.

  4. Click the Value box, and then type or select the criteria that you want.

  5. Click OK.

Delete a filter

  • In the Filter Criteria dialog box, hold down SHIFT while you click the the arrow in the leftmost column of each clause, and then press DELETE.

Modify a filter

  1. In the Filter Criteria dialog box, click an existing clause, and then do any of the following:

    • Click the Field Name box, and then click the field that contains the values that you want.

    • Click the Comparison box, and then click the operator that you want.

    • Click the Value box, and then type or select the criteria that you want.

  2. Click OK.

Add a clause to an existing filter

You can use multiple expressions in a single filter. You do this by adding new clauses that specify additional criteria that the data must satisfy.

  1. In the Filter Criteria dialog box, at the end of an existing clause, click the And/Or box, and then do one of the following:

    • To create a filter in which the data must match the criteria in both clauses, click And.

    • To create a filter where the data must match the criteria in only one clause, click Or.

  2. On the next row, click Click here to add a new clause.

  3. Click the Field Name box, and then click the field that contains the values that you want.

  4. Click the Comparison box, and then click the operator that you want.

  5. Click the Value box, and then type or select the criteria that you want.

  6. Click OK.

Group the clauses in a filter

When your filter contains multiple clauses, you may want to group two or more clauses so that they are applied before another clause.

  1. In the Filter Criteria dialog box, at the end of the second clause, click the And/Or box, and then click Or.

  2. In the Filter Criteria dialog box, click Click here to add a new clause.

  3. Click the Field Name box, and then click the field that contains the values that you want.

  4. Click the Comparison box, and then click the operator that you want.

  5. Click the Value box, and then type or select the criteria that you want.

  6. Hold down SHIFT while you click the arrows in the leftmost column of the clauses that you want to group, and then click Group. (To remove grouping, click Ungroup.)

    The sample expression in the Filter Criteria dialog box, including a bracket indicating the grouped clauses
    The bracket connecting two clauses indicates that those clauses are grouped.
  7. Click OK.

Modify a clause

  • In the Filter Criteria dialog box, click an existing clause, and then do any of the following:

    • In the Field Name box, click the field that contains the values that you want.

    • Click the Comparison box, and then click the operator that you want.

    • Click the Value box, and then type or select the criteria that you want.

    • Click OK.

Delete a clause

  • In the Filter Criteria dialog box, click the the arrow in the leftmost column of the clause that you want to delete, and then press DELETE.

Top of Page

Add or remove a sort order

When you sort the data in a data source, you modify the order in which the data appears. Sorting is a technique that you can use to rearrange records in a way that makes it easier for you to understand your data. Common sort orders include alphabetical and numerical.

You can also sort on multiple fields by adding more fields to the sort order list. When you sort on multiple fields, the sort order determines the order in which the sorting occurs and may affect the output of the data.

  1. On the Task Panes menu, click Data Source Library.

  2. In the Data Source Library task pane, click the data source that you want, and then click Properties.

  3. On the Source tab of the Data Source Properties dialog box, under Query, click Sort.

    Note: The options under Query are available only for the following SQL data sources: SharePoint lists and libraries, databases, and linked data sources that comprise two database tables in the same database. Also, if the data source uses a custom query, you see the Edit Custom Query button instead of options for Fields, Filter, and Sort. To delete a custom query, click Configure Database Connection, click Next, and then click Finish. In the Edit Custom SQL Commands dialog box, for each tab that displays an SQL statement, click Edit Command, and then delete the SQL statement.

    The Query section in the Daa Source Properties dialog box for a SharePoint list or library

    The Query section on the Source tab in the Data Source Properties dialog box.

  4. In the Data Source Properties dialog box, click Sort. The Sort dialog box appears.

You are now ready to add or remove a sort order.

Add a sort order

  1. In the Sort dialog box, under Available fields, click the field that you want to sort on, and then click Add.

  2. If no fields appear under Available fields, double-click More Fields, click the field that you want to sort on, and then click OK.

  3. Under Sort Properties, do one of the following:

    • To sort a field from lowest to highest (for example, A, B, C, or 1, 2, 3), click Ascending.

    • To sort a field from highest to lowest (for example, C, B, A, or 3, 2, 1), click Descending.

      Tip: To change the sort order of a field from ascending to descending (or vice versa), double-click the field in the Sort order list. Notice that the triangle next to the field name indicates whether a field is sorted in ascending or descending order.

  4. To sort on multiple fields, add more fields to the Sort order list.

  5. Click OK.

  6. You can also change the order in which the fields are sorted. To change the order of the fields, click a field in the Sort order list, and then click Move Up or Move Down.

Remove a sort order

  • In the Sort dialog box, under Sort order, click the field that you want to remove from the sort order, and then click Remove. To remove the entire sort from the database, remove all fields from the sort order.

Top of Page

No comments:

Post a Comment