How to: Use Queries in "Quadrant"

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

Instead of browsing database tables or folders manually in Microsoft code name “Quadrant”, you can use the query bar in a workpad to filter collections or to quickly select a particular record in the database quickly. “Quadrant” defaults to Microsoft code name “M” queries but can also take Visual Basic queries. For a guide to “M” query grammar, see Queries in "M". The topic uses sample data that is installed in How to: Install the "Quadrant" Sample Data.

Query Basics

To execute a query

  1. If you have not connected to the Repository database before, use the steps outlined in How to: Connect to a SQL Server Database with "Quadrant" to connect to the Repository database.

  2. If you have connected to the Repository database before, on the View menu, click Explorer, and click Repository.

  3. Expand the Database node.

  4. Expand the Microsoft.Samples.Organization node.

  5. Double-click the Tasks icon to open it in a new workpad. The new workpad displays all Tasks records in a table.

  6. Note the query bar below the Tasks header. The current value is the following query:

    Microsoft.Samples.Organization.Tasks
    

    When you double-click an item in the Explorer or a workpad, the content in the new workpad is always built from a query.

    If the Query bar is not visible when you open a workpad, right-click the workpad and click Query Bar. Alternatively, on the Workpad menu, click Show Query Bar.

  7. You can also use Visual Basic queries in the Query bar. The following query returns the same Tasks collection:

    vb(Database.GetRecords(Of Microsoft.Samples.Organization.Tasks )())
    
  8. The following “M” query returns all tasks that have a priority of “Low”:

    Microsoft.Samples.Organization.Tasks where value.Priority == 'Low'
    
  9. Press ENTER to execute the query.

    A customized table for the Tasks table is returned, showing only those with the priority "Low".

  10. The following query returns al high-priority tasks that are owned by the person whose first name is “Kim”:

    Microsoft.Samples.Organization.Tasks where  value.Priority == 'High' &&  value.Owner.FirstName == 'Kim'
    
  11. Press ENTER to execute the query.

  12. You can also perform a query for projections on tables by selecting and returning specific columns from a table. The following query returns only the Id and Subject columns from the Tasks table:

    Microsoft.Samples.Organization.Tasks select {Id=>value.Id,Subject=>value.Subject}
    
  13. Press ENTER to execute the query. Notice that only the Id and Subject columns for the Tasks table are displayed.

Session-aware Queries

In addition to performing queries in the workpad for a particular collection, you can also execute queries from an empty workpad.

A new workpad connects to the database that is associated with the previously active workpad. For example, if you are viewing data in the Repository database in a workpad, and you launch a new untitled workpad to perform additional queries, the untitled workpad can be used to search for data only in the Repository database. To search for data in another database, connect to that database first. If you have connected to that database before, either switch to a workpad that displays data from it, or on the View menu, click Explorer to open the session before using the untitled workpad.

To confirm that you are connected to the correct database before executing a query, look at the Session indicator in the status bar . For more information, see "Quadrant" Status Bar.

For more information about how you can manage open sessions and reconnect to a session, see How to: Connect to a SQL Server Database with "Quadrant".

To build a query in a new workpad

  • On the File menu, click New, and then click Workpad. An untitled workpad opens with an empty query bar.

  • If the Query bar is not shown by default when you open the workpad, right-click the workpad and select Query Bar in the context menu. Alternatively, in the Workpad menu, click Show Query Bar.

  • Look at the Session indicator in the status bar and confirm that you are connected to the Repository database.

  • Execute the queries from the previous section to generate identical results.

Multi-line queries

You can execute queries that are longer than one line in the query bar.

To add a line to the query bar

  • Press SHIFT+ENTER to add a new line to the query bar.

To scroll the query bar

  • Scroll the mouse wheel to scroll vertically in the query bar.

To expand the query bar

  • Drag the lower edge of the query bar to resize the height of the bar.

Query Errors

To fix query errors

  1. In the Tasks workpad, in the query bar, enter the following query:

    Microsoft.Samples.Organization.Tasks where  value.Priority == 'High' &&  value.Owner.FirstName == Kim
    
  2. Press ENTER to execute the query.

  3. An error message that say “Cannot resolve reference to Kim” appears below the query bar. This error occurs because the query string is missing quotation marks for the string.

  4. In the query bar, type the missing quotation marks around Kim and press ENTER to execute the corrected query.

See Also

Other Resources

Queries in "M"