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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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
 
Upvote 0
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
 
Upvote 0
Hi, try this:

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

Denis
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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
Back
Top