Saturday, October 17, 2020

Filter - SQL Query

The Filter - Search Records dialog uses AND criteria and asterisk wildcards.

The SQL Query Dialog can be used to create complex custom SQL searches or examine the SQL search syntax that was created using in the Filter - Search Records form..

Copy and Paste one the examples below to the Parts SQL Query form.  Edit the query statement as needed then select Run SQL Query to filter the Parts table.

SELECT *
FROM parts
WHERE parts.[Lib Report] <> ''
ORDER BY parts.[Lib Report];

SELECT *
FROM parts
WHERE parts.Part_Type="Resistor" OR parts.Part_Type="Capacitor" OR parts.Part_Type="Inductor";

SELECT *
FROM parts
WHERE parts.[Lib Report] Like '*'
ORDER BY parts.[Lib Report];

SELECT * 
FROM parts
WHERE ID >= 30015;

SELECT *
FROM parts
WHERE ID BETWEEN 30015 AND 30022;

SELECT *
FROM parts
WHERE parts.[Updated By] LIKE 'rclemmons' AND parts.ID BETWEEN 30015 AND 30022
ORDER BY parts.ID;

SELECT *
FROM parts
WHERE parts.[Updated By] LIKE 'rclemmons' AND parts.[Updated_Date] LIKE '*2020-10-19*'
ORDER BY parts.[ID], parts.[Updated By], parts.[Updated_Date];

SELECT *
FROM parts
WHERE Updated_Date >= '2020-10-16' AND Updated_Date <= '2021-11-16'
ORDER By parts.[Updated_Date];

SELECT *
FROM parts
WHERE parts.[Created By] = 'rclemmons' AND parts.Value = '1K'
ORDER BY parts.ID;

MS Access Examples using Brackets and Quotes: (Librarian Only)

UPDATE Parts SET Parts.[Supplier 1] = "";
UPDATE parts SET Parts.[Supplier 1] = 'DigiKey';

UPDATE parts SET parts.[Supplier 1] = 'DigiKey' WHERE parts.[Supplier 1] is NULL;
UPDATE parts SET parts.[Supplier 1] = 'DigiKey' WHERE parts.[Supplier 1] = 'Digi-Key';

DELETE FROM parts WHERE ID = 30512;
INSERT INTO parts (ID) VALUES (30512);

Select * FROM parts WHERE Sorted_Value IS NULL;
UPDATE parts SET Sorted_Value = 0

'Delete All Records in the Parts Table ! ! ! Warning ! ! !
DELETE FROM parts;

MySQL Syntax with `accent characters` : (Librarian Only)

'Delete All Records in the Parts Table ! ! ! Warning ! ! !
TRUNCATE parts.parts

UPDATE parts SET `Symbol Ref` = `Library Ref` WHERE `Symbol Ref` <> `Library Ref`;

UPDATE parts SET `Supplier 1` = ''
UPDATE parts SET `Supplier 1` = '' WHERE `Supplier 1` = 'DigiKey';
UPDATE parts SET `Supplier 1` = 'DigiKey' WHERE `Supplier 1` = '';

UPDATE parts SET `Supplier 1` = NULL
UPDATE parts SET `Supplier 1` = NULL WHERE `Supplier 1` = 'DigiKey';
UPDATE parts SET `Supplier 1` = 'DigiKey' WHERE `Supplier 1` IS NULL;

UPDATE parts SET `Supplier 1` = 'DigiKey' WHERE `Supplier 1` = 'Digi-Key';

'Adjust LIMIT equal to Row Count
UPDATE parts SET Sorted_Value = 0 WHERE Sorted_Value IS Null LIMIT 10000;

That's It !

No comments: