Friday, February 24, 2012

a query that doesnt work

Hi, im programming to a Database over Access2000, and i had done this
query:
SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
#03/05/2006 10:57:45# and #03/05/2006 12:57:45#
the answer is null, but if i use a query like that
SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
date1 and date2
and instead of variables use the literals (#03/05/2006 12:57:45#) it
works.
i dont know why, can someone help me
Sorry for my english i know there are a lot of mistakes on it.
Thanks every oneIf you're connecting to a SQL Server database - and that's what this
newsgroup is about - use single quotes to delimit datetime constants:
SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
'03/05/2006 10:57:45' and '03/05/2006 12:57:45'
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"Bardanca" <Bardanca@.gmail.com> wrote in message
news:1146655492.968842.253080@.v46g2000cwv.googlegroups.com...
Hi, im programming to a Database over Access2000, and i had done this
query:
SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
#03/05/2006 10:57:45# and #03/05/2006 12:57:45#
the answer is null, but if i use a query like that
SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
date1 and date2
and instead of variables use the literals (#03/05/2006 12:57:45#) it
works.
i dont know why, can someone help me
Sorry for my english i know there are a lot of mistakes on it.
Thanks every one|||Bardanca (Bardanca@.gmail.com) writes:
> Hi, im programming to a Database over Access2000, and i had done this
> query:
> SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
> #03/05/2006 10:57:45# and #03/05/2006 12:57:45#
> the answer is null, but if i use a query like that
> SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
> date1 and date2
> and instead of variables use the literals (#03/05/2006 12:57:45#) it
> works.
> i dont know why, can someone help me
You are better off asking in an Access newsgroup, as there are considerable
differences between Access and SQL Server.
The obvious thing I would think of is regional settings. Is that May 3rd
or March 5th?
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Tom Moreau (tom@.dont.spam.me.cips.ca) writes:
> If you're connecting to a SQL Server database - and that's what this
> newsgroup is about - use single quotes to delimit datetime constants:
> SELECT Sum(Importe) As SumaDia FROM [Diario Caja] WHERE Fecha between
> '03/05/2006 10:57:45' and '03/05/2006 12:57:45'
And use a date format of YYYYMMDD, as the above could be interpreted as
May 3rd or March 5th depending on settings. YYYYMMDD is unambiguous.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

No comments:

Post a Comment