Hi,
i store dates in a smalldatetime field. Now i want to retrieves all records
between 2 dates
SELECT * FROM myTable WHERE addDate BETWEEN '2005/7/24' AND '2005/7/25'
(suppose to retrieve all records added yesterday and today.)
I get no error but get no results back ?
What do i wrong ?
Grard.I discover when i add the time it works. How can i work only with the date ?|||Don't use BETWEEN, and use a sensible and unbambiguous date format.
WHERE addDate >= '20050724' AND addDate < '20050726'
For more info, see
http://www.aspfaq.com/2280
http://www.aspfaq.com/2023
http://www.karaszi.com/SQLServer/info_datetime.asp
"Grard Leclercq" <gerard.leclercq@.pas-de-mail.fr> wrote in message
news:iz9Fe.153365$LX6.8091701@.phobos.telenet-ops.be...
> Hi,
> i store dates in a smalldatetime field. Now i want to retrieves all
> records between 2 dates
> SELECT * FROM myTable WHERE addDate BETWEEN '2005/7/24' AND '2005/7/25'
> (suppose to retrieve all records added yesterday and today.)
> I get no error but get no results back ?
> What do i wrong ?
> Grard.
>
>|||You may need to allow for addDate having times other than midnight. Also,
use a safe date format rather than rely on SQL Server interpreting your
local date format correctly:
SELECT *
FROM myTable
WHERE addDate >= '20050724'
AND addDate < '20050725' ;
David Portas
SQL Server MVP
--|||CORRECTION:
SELECT *
FROM myTable
WHERE addDate >= '20050724'
AND addDate < '200507256' ;
David Portas
SQL Server MVP
--|||Ok, now i understand difference with Access. Thx everybody. Gerard
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment