The advanced find allows you to create custom finds.
Click the Find button in the toolbar.
Click the Advanced tab.
Click the Query Builder button in the toolbar.
Enter your query.
Click OK.
Click Exec button in the toolbar or the Exec button on the right in the Find window.
Advanced functions allow you to filter results and/or get user input to add to you find.
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.
SELECT * FROM tblOrder WHERE DueTimeTo = '{{{ Please choose a due date. }}}' |
The description "Please choose a due date" can be changed. |
Return orders for a certain date.
DECLARE @Calendar AS DateTime SET @Calendar = '{{{ Please choose a due date. }}}' SELECT * FROM tblOrder WHERE DueTimeTo BETWEEN @Calendar AND @Calendar + 1 |
Convert server date and time to local date and time based on the zip code.
SELECT dbo.localizedate (DateTime, '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
|
Convert the server date and time based on the zip code 85002 into the 1 format (MM/DD/YY) to get 09/04/20.
SELECT CONVERT(VARCHAR(30), dbo.localizedate (GETDATE(), '85002'), 1); |
Allow the user to select from a list of values that can be passed in to filter results.
[[[ Choose order type. | SELECT OrderTypeID, Description FROM tblOrderTypes ]]] |
There are two values.
OrderTypeID which will be passed into the find.
Description of the drop down results.
This is why OrderTypeID a numeric value comes before the description which is displayed as the list of choices in the drop down box. |
Return all orders with a particular order type.
SELECT * FROM tblOrder WHERE OrderType = '[[[ Please choose and order type. | SELECT OrderTypeID, Description FROM tblOrderTypes ]]]' |
Input Box
Capture any value from the user and pass it into the find to filter your results.
'<< Please Enter a route zone number. >>' |
Find all zip codes in the zones table where RouteZone1 equals what is entered into the input box function.
SELECT * FROM tblZones WHERE RateZone1 = '<< Please enter a rate zone number. >>' |
Filter the results by the business units available to the user without user input.
Business units available to the user are set by the user's permissions. See Users (Classic Operations App) and User Permissions - Definitions (Classic Operations App) for more information. |
{{BusinessUnits}} |
The business units available are loaded into a comma separated list.
Filter orders by business unit.
SELECT * FROM tblOrder AS O INNER JOIN tblCustomer C WITH(NOLOCK) ON O.CustID = C.CustID WHERE O.OrderID > '125000' AND C.BusinessUnitID IN ({{BusinessUnits}}) |
Filter results by the user that made an edit to a database record.
{{UserID}} |
Filter orders created by the current Operations App user.
SELECT * FROM tblOrder O WHERE O.CreatedBy = '{{UserID}}' |
Return the current Operations App user.
DECLARE @User VARCHAR(20) SET @User = '{{UserID}}' SELECT @User |
If you are modifying a query create a backup copy.
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.
|
Ignoring max records can lock up the system. See Best Practices WITH(NOLOCK) above. |
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.*
--EXEC |
*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.
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.
SET NOCOUNT ON |
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.
SET NOCOUNT OFF |
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.
SET ANSI_WARNINGS OFF |
"ÆÆ" (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.
|