Select Distinct Sql statement

jjsteele

New Member
Joined
Oct 5, 2004
Messages
35
I have used this example http://www.mrexcel.com/board2/viewtopic.php?t=94118&highlight=combo to select data using 3 combo boxes. But I need it to only show data that has a checkbox ticked. I have tried adding in another variable to the sql statement but it gives an error of too complicated?

This is my orignal sql statement from the first combobox

Code:
SELECT DISTINCT [tblAppointmentSlots].[TestLocation] FROM tblAppointmentSlots WHERE ((([tblAppointmentSlots].[Available])='Yes')) And ((([tblAppointmentSlots].[Test])=[txtTest]));

This is my modded version, I am trying to make it only show distinct values where available (checkbox) is ticked or yes.

Code:
SELECT DISTINCT [tblAppointmentSlots].[TestLocation] FROM tblAppointmentSlots WHERE ((([tblAppointmentSlots].[Test])=[txtTest]));

jjsteele
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
Looks like you grabbed the wrong statement to delete -- try
Code:
SELECT DISTINCT [tblAppointmentSlots].[TestLocation] FROM tblAppointmentSlots WHERE (([tblAppointmentSlots].[Available])='Yes'));

By the way, did you do this in straight SQL or using the graphical query interface? If you're just getting started with SQL, I'd recommend the interface first. Get the query doing pretty well what you need, then go to SQL view and add the DISTINCT keyword to give you the unique values.

Denis
 

jjsteele

New Member
Joined
Oct 5, 2004
Messages
35
Ok got the code round the wrong way but corrected below with a better explaination.

This is my orignal sql statement from the first combobox

Code:
SELECT DISTINCT [tblAppointmentSlots].[TestLocation] FROM tblAppointmentSlots WHERE ((([tblAppointmentSlots].[Test])=[txtTest]));

So I am saying for the combo box show distinct testlocation values from the tblAppointmentSlots Table where the value of test is equal to the value in txtTest Textbox. Thats All fine and works as required

This is my modded version, I am trying to add the additional requirement of the value in available of tblAppointmentSlots table equal to yes (as its a tickbox). Its this code that does not work


Code:
SELECT DISTINCT [tblAppointmentSlots].[TestLocation] FROM tblAppointmentSlots WHERE ((([tblAppointmentSlots].[Available])='Yes')) And ((([tblAppointmentSlots].[Test])=[txtTest]));


jjsteele
 

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
Hi, try this:

Code:
SELECT DISTINCT [tblAppointmentSlots].[TestLocation] FROM tblAppointmentSlots WHERE ((([tblAppointmentSlots].[Available])='Yes')) And ((([tblAppointmentSlots].[Test])=TRUE));

Denis
 

Forum statistics

Threads
1,141,720
Messages
5,708,078
Members
421,545
Latest member
TWR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top