3. Conditions

3. Conditions


We can use WHERE condition to filter the records. 

SELECT wo.WORKORDERID "Request ID",
       std.STATUSNAME "Request Status" FROM WorkOrder wo
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID
WHERE std.STATUSNAME = 'open'

  


Operators in WHERE clause:

 

= Equal

<> Not equal. Note: In some versions of SQL this operator may be written as !=

> Greater than

< Less than

>= Greater than or equal

<= Less than or equal



AND and OR Operators:

 

The WHERE clause can be combined with AND and OR operators.

The AND and OR operators are used to filter records based on more than one condition:


  • The AND operator displays a record if all the conditions separated by AND are TRUE.


                    (cd.CATEGORYNAME = 'Hardware'  AND  std.STATUSNAME = 'open')



  • The OR operator displays a record if any of the conditions separated by OR is TRUE.


                  (cd.CATEGORYNAME = 'Hardware'  OR  std.STATUSNAME = 'open')


Combination of AND and OR:

((cd.CATEGORYNAME = 'Hardware' AND std.STATUSNAME = 'open') OR (ti.FIRST_NAME = 'Howard'))




LIKE Operator 


The LIKE operator can be used in the conditional selection of the where clause. The percent sign "%" can be used as a wild card to match any possible character that might appear before or after the characters specified. For example: 

(cd.CATEGORYNAME LIKE '%Hardware%')

WHERE cd.CATEGORYNAME LIKE 'a%'  - Finds any values that start with "a" 
WHERE cd.CATEGORYNAME LIKE '%a'  - Finds any values that end with "a"
WHERE cd.CATEGORYNAME LIKE '%are%'  - Finds any values that have "are" in any position


IN Operator

The IN operator allows you to specify multiple values in a WHERE clause.

cd.CATEGORYNAME IN ('hardware','printer','software')


                  New to ADSelfService Plus?

                    • Related Articles

                    • How to restrict adding of notes by users

                      1. Go to Admin > Page Scripts: 2. Create New Rule > configure if it needs specifically for Technicians or Requesters or All Users and set the Event > Conditions as per your requirement 3. Under Actions > Execute Script > Make use of the below script: ...
                    • Hide Rocket Notification Icon

                       Please follow the below mentioned from build 10600 and above: 1. Go to Admin > Page Scripts > click 'New Rule'. Give the rule a suitable name. 2. Define the conditions as per your requirement. 3. Under Actions click 'Write Custom Script' and paste ...
                    • Script to auto-populate the task owner field with the technician who created the request

                      REQUIREMENT: When a technician creates a request and a task is added under the request, the task owner should be the same technician. TESTED IN: Builds 14503 (Postgres) STEPS: 1) Under "Admin" > "Task Custom Functions," create a new custom function ...
                    • 1. Query Basics

                      Basic Query: SELECT wo.WORKORDERID AS "Request ID", wo.TITLE AS "Subject", aau.FIRST_NAME AS "Requester", ti.FIRST_NAME AS "Technician", cd.CATEGORYNAME AS "Category", std.STATUSNAME AS "Request Status" FROM WorkOrder wo LEFT JOIN SDUser sdu ON ...
                    • How does suggested Owner feature works ?

                      If you Auto Assign Owners for assets it will assign owners based on the last logged in user for that Asset. The Suggested owner will be listed only if the below conditions are met, 1. Windows machines should have been scanned successfully. 2. The ...