Can I have some SQL tech support please?
Aug. 9th, 2006 04:49 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I'll start with a disclaimer: I am not very good at SQL. I don't use it much.
So, can anyone tell me why the following query isn't working?
USE [DATABASE]
GO
SELECT *
FROM [TABLE]
WHERE [DATETIME FIELD] BETWEEN [FIRST DATE] AND [LAST DATE]
GO
SQL accepts and runs the query but brings back zero results even though I know there are records that should fall into the range. I note that the display of the datetime field in Enterprise Manager is dd/mm/yyyy and that in a Query Result Pane it is yyyy-mm-dd. I have tried both of these, but no success. The exact same query runs fine on a numeric field, so my syntax is OK. What am I doing wrong?
So, can anyone tell me why the following query isn't working?
USE [DATABASE]
GO
SELECT *
FROM [TABLE]
WHERE [DATETIME FIELD] BETWEEN [FIRST DATE] AND [LAST DATE]
GO
SQL accepts and runs the query but brings back zero results even though I know there are records that should fall into the range. I note that the display of the datetime field in Enterprise Manager is dd/mm/yyyy and that in a Query Result Pane it is yyyy-mm-dd. I have tried both of these, but no success. The exact same query runs fine on a numeric field, so my syntax is OK. What am I doing wrong?
no subject
Date: 2006-08-09 04:08 pm (UTC)no subject
Date: 2006-08-09 04:09 pm (UTC)Have you fixed it?
Date: 2006-08-30 11:30 am (UTC)In my case it was to do with the date format - I had to output the date in ODBC format, then analyze it. My solution wouldn't solve your problem (as it was in Cold Fusion based code calling data from SQL server) but I recommend pursuing the date format angle if you haven't solved it already!
Apologies for inappropriate spamming if this is no use to you.
Re: Have you fixed it?
Date: 2006-08-30 02:05 pm (UTC)I didn't actually work out exactly why it didn't work in the end. I found an online help page that displayed the query. It looked EXACTLY the same as mine. However, when I copied and pasted the date format from that query to mine and carefully replaced the example dates with my dates it worked.
I still have no idea why.