user2241865 user2241865 - 10 days ago 6
SQL Question

How build Query String

I need to build query strings for the following questions -


  1. Display records where the batch codes are on Sun and from Jamnagar City and Reliance only.

  2. Display records where the batch codes are on Sun and from Jamnagar City, Reliance and TATA only.



My weekly Access table -

batch_code bday duration period_no branch
B001 Sun 1 2 Jamnagar City
B001 Mon 1 2 Jamnagar City
B001 Tue 1 2 Jamnagar City
B002 Mon 1.3 4 TATA
B002 Mon 1.3 4 TATA
B003 Sun 1 1 Jamnagar City
B003 Mon 1 1 Jamnagar City
B004 Sun 2 2 Reliance
B004 Mon 2 2 Reliance
B004 Tue 2 2 Reliance
B005 Sun 2 2 TATA
B005 Mon 2 2 TATA
B005 Tue 2 2 TATA
B006 Sun 1.3 4 Jamnagar City
B007 Wed 1.3 4 Jamnagar City

Answer
  1. SELECT * FROM YourTableName WHERE bday='Sun' AND (branch='Jamnagar City' OR branch='Reliance')

  2. SELECT * FROM YourTableName WHERE bday='Sun' AND (branch='Jamnagar City' OR branch='Reliance' OR branch='TATA')

I believe you can use the IN command, but I'm not positive if it works in Access. You can try it though. Syntax would be:

SELECT * FROM YourTableName WHERE bday='Sun' AND branch IN ('Jamnagar City', 'Reliance', 'TATA')