Advanced Functions

Advanced functions allow you to filter results and/or get user input to add to your find.

Calendar Function

Display a calendar to the user when they run the find from which they can select the date instead of typing it. This will help eliminate example date formats and bad input. 

The description "Please choose a due date" can be changed.

Example

Return orders for a certain date.

Localized Date Function 

Convert server date and time to local date and time based on the zip code. 

Change DateTime to the datetime needing to be localized, and ZipCode to the zip code to use to determine the timezone for localizing the datetime value. Using the statement above will result in a YY-MM-DD hh:mm:ss.s. For example, the date output would be 2020-09-04 17:17:20.887.

Quick Tips

  • Canadian postal codes can use just the first three characters.

  • Search “SQL Date and Time Conversions”, on the internet, to find a list of format codes.

Example

Convert the server date and time based on the zip code 85002 into the 1 format (MM/DD/YY) to get 09/04/20.

Sub Select Drop Down Box

Allow the user to select from a list of values that can be passed in to filter results.

There are two values.

  1. OrderTypeID which will be passed into the find. 

  2. Description of the drop down results.  

This is why OrderTypeID a numeric value comes before description which is displayed as the list of choices in the drop down box.

Example

Return all orders with a particular order type.

Input Box

Capture any value from the user and pass it into the find to filter your results.

Example

Find all zip codes in the zones table where RateZone1 equals what is entered into the input box function.

Business Unit Filtering

Filter the results by the business units available to the user without user input.  

Quick Tip: Business units available to the user are set by the user's permissions. See Permissions and Permissions - Definitions for more information.

The business units available are loaded into a comma separated list.

Example

Filter orders by business unit.

User ID

Filter results by the user that made an edit to a database record.

Example 1

Filter orders created by the logged in user. 

Example 2

Return the current X Dispatch user. 

Useful Information

Best Practices

  • If you are modifying a query create a backup copy prior to making any modifications. 

  • Add a header, or snippet, to note the creator, creation date, changelog, and other useful information.

  • Use WITH(NOLOCK) to avoid locking.

  • See W3Schools' SQL Tutorial more references on SQL.

  • If you are creating more advanced scripts you can send them to Technical Support for code review.

  • Use a static variable instead of indeterminant functions in WHERE clause.

If you want to get the order ID and current timestamp of all the orders that will be ready in the future, you should use a determinant, instead of using dbo.GetCXTDate() which is an indeterminant function where the value would change every millisecond.

If you want to get the order ID and yesterday’s date of all the orders that were or will be ready starting yesterday, you should use a determinant.

Ignore Max Records Restrictions

Place the following in the query as its own line will cause the query to ignore any max records restrictions. Grids have a limitation of 250,000 rows, and any dataset that exceeds this will not be visible.*

*A possible solution to view datasets over 250,000 is selecting the last row of the recordset and clicking the column header which will reorder the dataset and make all rows visible.

Multiple Select Statements

SQL will return the number of records returned for every select statement that is executed in a batch execution. ADO only allows for one record count to be returned for it to return results.  If you have a query that requires multiple select statements, you will need to disable returning the number of records affected until the last select statement.

To disable the returning of the number of records affected, you will need to place the following on its own line before any select statements are executed. 

When you reach the last select statement, you need to add the following on its own line before the last select statement begins to re-enable the record count. 

Disable Warnings

SQL will return any warnings that may occur during the execution such as summing a column that may contain NULL values, and ADO will not return the data properly if any warnings are present. To get around this, place the following on its own line before any select statements. 

For Developers and/or Administrators

"ÆÆ" (ALT + 1 + 4 + 6)x2 - Placing this string in the front of a query will allow for Inserts into tables, dropping columns and tables, etc.

"ææ" (ALT + 1 + 4 + 5)x2 - This has the same functionality as "ÆÆ", but the string is removed from the query once the query is run.