Date problem

Date problem

Post by Kit » Sun, 16 Jul 2000 04:00:00



I use MS SQL 6.5 Developer Edition. I have problem when I try to query
data base on date. It seems like the query didnt care about year. I
dont know SQL 6.5 has problems with Y2K problem or not. Please take a
look at my query.

First I use
SELECT convert(char(12),orddate,101) as dd FROM tblorder WHERE
convert(char(12),orddate,101) between '02/16/1999' and '07/16/2000'
I get result
DD           |
---------------
07/12/2000   |
07/12/2000   |

---------------
2 rows have been shown

Second I change date from 02/16/1999 to 07/16/1999
SELECT convert(char(12),orddate,101) as dd FROM tblorder WHERE
convert(char(12),orddate,101) between '07/16/1999' and '07/16/2000'
No matter what year I change from 1999,2000,2001, or whatever. It
returns NULL.

Can someone tell me why I have problem with year? Please help me. I'm
really new to SQL

Kit

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!

 
 
 

Date problem

Post by BPMargoli » Mon, 17 Jul 2000 04:00:00


Kit,

Your WHERE clause is doing comparisons on character data, not datetimes. When
you use CONVERT to "format" orddate, you are also changing the data type.

Try something more along the lines of ...

WHERE orddate >= '07/16/1999'
AND      orddate  < '07/17/2000'

---------------------------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which can be
cut and pasted into Query Analyzer is appreciated.


Quote:> I use MS SQL 6.5 Developer Edition. I have problem when I try to query
> data base on date. It seems like the query didnt care about year. I
> dont know SQL 6.5 has problems with Y2K problem or not. Please take a
> look at my query.

> First I use
> SELECT convert(char(12),orddate,101) as dd FROM tblorder WHERE
> convert(char(12),orddate,101) between '02/16/1999' and '07/16/2000'
> I get result
> DD           |
> ---------------
> 07/12/2000   |
> 07/12/2000   |

> ---------------
> 2 rows have been shown

> Second I change date from 02/16/1999 to 07/16/1999
> SELECT convert(char(12),orddate,101) as dd FROM tblorder WHERE
> convert(char(12),orddate,101) between '07/16/1999' and '07/16/2000'
> No matter what year I change from 1999,2000,2001, or whatever. It
> returns NULL.

> Can someone tell me why I have problem with year? Please help me. I'm
> really new to SQL

> Kit

> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
> The fastest and easiest way to search and participate in Usenet - Free!


 
 
 

1. MDX: year-to-date/month-to-date problem

I am having trouble subtracting the year-to-date totals at the quarter
through the month levels of a time dimension to
calculate the month-to-date totals.

I am using the previousmember and currentmember functions, but I cannot make
the calculation use the year-to-date
totals only at the first member of the level (January for month, 1 for
quarter).  For January, the calculation is taking the YTD amount
for the current year minus the YTD amount from the previous year, obviously
incorrect.

                                                         - Thanks, Mike
Parry (MDX novice)

2. DELETE FILE doesn't delete the file

3. Date problem- date calculation in between values

4. pb with sql

5. date problems

6. RAS and SQL Server CE

7. MSSQL server English-Turkish Date Problem

8. ODBC SQLPrepare problem

9. Date problem with SQL Server

10. Please Help: Need SQL Server ODBC client v3.60.x to correct a date problem

11. BCP date problems with SQL7.0

12. Date Problem

13. could date problem cause log truncation failures?