basic logic, sql statements and/or you a quick tour of basic logic and how to evaluate logical...
DESCRIPTION
Statement of Truth (Not!) Evaluations can also be based on numerical values: NumCat = 1 NumBike < 1 TRUE FALSETRANSCRIPT
![Page 1: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/1.jpg)
Basic Logic, SQL Statements AND/OR You
A quick tour of basic logic and how to evaluate logical expressions and
implement simple SQL queries.
![Page 2: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/2.jpg)
Statement of Truth (Not!)
The statement is the foundational basis for logic. Is the statement TRUE or FALSE?
Cat = Black
Bike = Red
TRUE
FALSE
![Page 3: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/3.jpg)
Statement of Truth (Not!)
Evaluations can also be based on numerical values:
NumCat = 1
NumBike < 1
TRUE
FALSE
![Page 4: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/4.jpg)
We know its value, now what?
Statement can be combined using the following conjunctions:
• AND• OR• NOT• Others…
![Page 5: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/5.jpg)
AND Truth Table
X Y X AND Y
False False
True False
False True
True True
FALSE
FALSE
FALSE
TRUE
![Page 6: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/6.jpg)
OR Truth Table
X Y X OR Y
False False
True False
False True
True True
FALSE
TRUE
TRUE
TRUE
![Page 7: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/7.jpg)
NOT Truth Table
X NOT X
False
True
TRUE
FALSE
![Page 8: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/8.jpg)
Other Truths
• NAND = NOT AND: (Inverts AND result)
• NOR = NOT OR: (Inverts OR result)
• XOR: True if only one operator is true
![Page 9: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/9.jpg)
Conditionals
How to compare to values.
![Page 10: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/10.jpg)
Conditional Statements
• Equal• Not Equal• Greater Than• Less Than• Greater Than or Equal To• Lesser Than or Equal To• Like
=< > “≠”><>= “≥”<= “≤”Like
![Page 11: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/11.jpg)
=< >><>=<=Like
X = 4X < > 9Y > 2X < 1 BazillionX >= 4Y <= 7Z Like “Do%”
Conditional Statements
Set Values:X=4Y=5Z=“Dog”
![Page 12: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/12.jpg)
Examples
![Page 13: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/13.jpg)
Example 1:
(Cat = Black) AND (Bike = Red)
FALSE
![Page 14: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/14.jpg)
Example 2:
(Cat = Yellow) OR (NumBike > 1)
FALSE
![Page 15: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/15.jpg)
Example 3:
(Cat <> Grey) OR (Bike = Green)
TRUE
![Page 16: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/16.jpg)
Example 4:
(NumCat <= 2) AND (Bike = Blue)
TRUE
![Page 17: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/17.jpg)
Example 5:
NOT (Cat Like “Ca%”)
FALSE
![Page 18: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/18.jpg)
Example 6:
NOT ((NumCat < 10) AND (Bike Like “Blu%))OR ((NumCat <= NumDog) OR (Bike = Blue))
TRUE
![Page 19: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/19.jpg)
Basic SQL Statement
![Page 20: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/20.jpg)
Bare Minimums
SELECT fieldname 1, fieldname 2, ...fieldname n
FROM tablename
![Page 21: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/21.jpg)
Adding Conditionals
SELECT fieldname 1, fieldname 2, ...fieldname n
FROM tablenameWHERE (fieldname conditional value)
logic_operand (fieldname conditional value) ...
![Page 22: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/22.jpg)
Adding Sort Values
SELECT fieldname 1, fieldname 2, ...fieldname n
FROM tablenameWHERE (fieldname conditional value)
logic_operand (fieldname conditional value) ...
ORDER BY fieldname
![Page 23: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/23.jpg)
SQL Statement Examples
![Page 24: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/24.jpg)
Generic Report 2
SELECT RequestNumber, ResourceName AS Name, Agency, KindCode AS Kind, Trainee as T, UnitID, CheckinDate, CheckinTime
FROM vBasicRptsWHERE kindcode like 'hc%' or kindcode =
'cc'ORDER BY RequestNumber
![Page 25: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/25.jpg)
Crew Query
SELECT RequestNumber, ResourceName AS Crew
FROM vBasicRpts WHERE Status <> 'D' AND Agency = 'BIA'
and KindCode in ('HC1', 'HC2')
![Page 26: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/26.jpg)
Personnel Count by Agency
SELECT Agency, COUNT(*) AS [Agency Count], SUM(NumberPersonnel) AS NumberPersonnel
FROM vBasicRpts GROUP By Agency
![Page 27: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/27.jpg)
DIVS Checkin
SELECT ResourceName, CheckinDate FROM vBasicRpts
WHERE KindCode = 'DIVS' and CheckinDate between '05/15/07' and '05/20/07'
ORDER BY ResourceName
![Page 28: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/28.jpg)
Just For Grins…
The following query is an example of how to perform a selection statement from multiple tables as well as a method of minimizing the amount of typing needed when specifying those tables.
The query itself is designed to produce a list of records that has Accounting Codes that are set incorrectly. Note: Make sure you understand all components of this query before using on an active database. You must accept all responsibility for it’s use.
![Page 29: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/29.jpg)
Just For Grins…SELECT C.RequestNumber, C.ResourceName, C.AgencyCode,
C.HomeUnit, C.SectionDesc, C.KindCode, C.ActivityDate, C.AccountingCode, C.AccrualCode, B.Status
FROM vCost C ,VBasicRpts BWHERE (C.RequestNumber = B.RequestNumber ) and (B.Status like 'C')
and (C.RequestNumber like 'c%' or C.RequestNumber like 'o%') and not ((C.AccountingCode like 'paxy99' and C.AccrualCode like 'STO') or (C.AgencyCode like 'BIA' and C.AccountingCode like 'xy99') or (C.AgencyCode like 'BLM' and C.AccountingCode like 'xy99') or (C.AgencyCode like 'NPS' and C.AccountingCode like 'xy99') or (C.AgencyCode like 'FWS' and C.AccountingCode like 'xy99')or (C.AgencyCode like 'FS' and C.AccountingCode like 'paxy99')or ((C.AgencyCode like 'PVT' or C.AgencyCode like ‘CA') and
( C.AccountingCode like ‘99999') or (C.AccountingCode like ‘99998')))
ORDER BY AgencyCode
![Page 30: Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries](https://reader033.vdocuments.site/reader033/viewer/2022051710/5a4d1af47f8b9ab059980158/html5/thumbnails/30.jpg)
Questions?