Whats wrong with Query Syntax, not returning proper set

ilcaa

Well-known Member
Joined
May 25, 2005
Messages
751
Office Version
  1. 365
Platform
  1. Windows
I definetly have the data in my DB because I can see it, but this query will not return the right data.

I basically want to return the top 5 data points before this date (earlier) but including the date.

select TOP 5 qDate, from Quotes WHERE qTicker='goog' and qDate <= #3/17/2015# ORDER BY qDate DESC;

so this should return.

3/17/2015
3/16/2015
3/13/2015
3/12/2015
3/11/2015

*please note, it doesn't return 3/15 or 3/14 because it doesn't exist in my database. So starting with x date return this date (data point) and the 4 previous dates (or data points within qDate field)
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You have an error in your SQL code. There should not be a comma after the word "qDate".
Also make sure that the data type of the qDate field is Date and not Text.
 
Upvote 0
its not that it returns an error, is just doesnt return the right data set. It results do not start with the date specified in the query (3/17/2015), also the column is a Date colume with short-date

where is the error in the Syntax? which qDate in the query are you referrring to that is missing the comma?
 
Upvote 0
The comma at the end of this part:
Code:
[COLOR=#333333]select TOP 5 qDate[/COLOR][COLOR=#ff0000][B],[/B][/COLOR]
should NOT be there.

Can you tell me what this query returns?
Code:
[COLOR=#333333]select count(*) from Quotes WHERE qTicker='goog' and qDate <= #3/17/2015#;[/COLOR]
 
Upvote 0
sorry I mis-read your post about the comma. The count return of your query is 231,
 
Upvote 0
OK, so that selection criteria finds 231 records. And what happens if you run this:
Code:
[COLOR=#333333]select TOP 5 qDate from Quotes WHERE qTicker='goog' and qDate <= #3/17/2015# ORDER BY qDate DESC;[/COLOR]
Does it return nothing at all, or just unexpected results?
If unexpected results, what does it return?
 
Upvote 0
thanks for trying to help out, I appreciate it. I ended up deleting the Access DB, downloaded all the data from scratch and was able to get it to work properly. your query above returns the right values, thanks again
 
Upvote 0

Forum statistics

Threads
1,221,864
Messages
6,162,497
Members
451,770
Latest member
tsalaki

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