Subject Re: RESTARTED [firebird-support] SELECT ... WHERE ... BETWEEN using TIMESTAMP felds
Author Svein Erling Tysvaer
Hi Fabio!

I tried creating LSV and inserting the values (some minor problems in
that I had to change DESCRIZIONE1 to DESCRIZIONE and use a different
date format) and then I added another table ART with random values
(except that I used the same values for CODICE as you put in LSV).

Your query then returned me five rows, just as it should.

The one thing I do notice, is that you tell us to insert values into
LSV, but in your query you ask for ART.DATA_ORA. It isn't simply that
you mix up ART.DATA_ORA and LSV.DATA_ORA, that they may differ and that
what Firebird returns is correct? I've at least experienced myself that
apparently strange results sometimes have simple explanations (I
remember it took me a little while to see my error when I used wbere
rather than where)...

Set

Codebue Fabio - P-Soft wrote:
> I have a table like this
>
> CREATE TABLE LSV (
> ART_CODICE VARCHAR(20) DEFAULT '' ,
> DESCRIZIONE VARCHAR(40),
> DATA_ORA TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
> PREZZO NUMERIC(18,6) DEFAULT 0
>
> );
>
> INSERT INTO LSV (ART_CODICE, DESCRIZIONE1, DATA_ORA, PREZZO) VALUES
> ('CDC.KR.XQ', 'POWER LINE KRAUN 200MBPS BRIDGE HOMEPLUG', '25-OCT-2008
> 05:18:40', 65);
> INSERT INTO LSV (ART_CODICE, DESCRIZIONE1, DATA_ORA, PREZZO) VALUES
> ('CDC.ZY.66', 'ROUTER ADSL2+ ZYXEL WI-FI PRESTIGE 660HW', '25-OCT-2008
> 05:18:40', 79);
> INSERT INTO LSV (ART_CODICE, DESCRIZIONE1, DATA_ORA, PREZZO) VALUES
> ('CDC.HS.14', 'STAMPANTE HP DESKJET 6940', '30-MAR-2009 08:47:16', 90);
> INSERT INTO LSV (ART_CODICE, DESCRIZIONE1, DATA_ORA, PREZZO) VALUES
> ('CDC.86.HV', 'NB HP PAVILION DV7-1110EL', '20-APR-2009 13:48:09', 930);
> INSERT INTO LSV (ART_CODICE, DESCRIZIONE1, DATA_ORA, PREZZO) VALUES
> ('CDC.KR.3W', 'KRAUN KIT ROUTER ADSL2/2+ WI-FI + USBKEY', '20-APR-2009
> 13:53:16', 59);
> INSERT INTO LSV (ART_CODICE, DESCRIZIONE1, DATA_ORA, PREZZO) VALUES
> ('CDC.SE.23', 'HDD SEAGATE 160GB PATA 7200RPM', '20-APR-2009 13:55:11',
> 42.5);
> INSERT INTO LSV (ART_CODICE, DESCRIZIONE1, DATA_ORA, PREZZO) VALUES
> ('CDC.WD.86', 'HDD ESTERNO WD MY BOOK ESSENTIAL 1TB', '20-APR-2009
> 13:56:57', 105);
>
> When I try to run this SQL code:
>
> Select Art.DATA_ORA,Art.Codice,Art.Descrizione1,Lsv.Prezzo from Lsv,ART
> where LSV.ART_CODICE=ART.CODICE
> AND LSV.DATA_ORA between CAST('03/20/2009 00:01:00' AS TIMESTAMP) and
> CAST('04/20/2009 23:59:00' AS TIMESTAMP)
> ORDER BY DATA_ORA
>
> I obtain
>
> DATA_ORA CODICE DESCRIZIONE1
> PREZZO
> 25/10/2008 5.18.40 CDC.KR.XQ POWER LINE KRAUN
> 200MBPS BRIDGE HOMEPLUG 65
> 25/10/2008 5.18.40 CDC.ZY.66 ROUTER ADSL2+ ZYXEL
> WI-FI PRESTIGE 660HW 79
> 30/03/2009 8.47.16 CDC.HS.14 STAMPANTE HP DESKJET
> 6940 90
> 20/04/2009 13.48.09 CDC.86.HV NB HP PAVILION
> DV7-1110EL 930
> 20/04/2009 13.53.16 CDC.KR.3W KRAUN KIT ROUTER
> ADSL2/2+ WI-FI + USBKEY 59
> 20/04/2009 13.55.11 CDC.SE.23 HDD SEAGATE 160GB
> PATA 7200RPM 42,5
> 20/04/2009 13.56.57 CDC.WD.86 HDD ESTERNO WD MY
> BOOK ESSENTIAL 1TB 105
>
> I don't have to retrieve first two lines?
> Any idea?
>
>
> Codebue Fabio
> .--------------------------------.
> P-Soft di Codebue Fabio & C. sas
> via B.Storti, 19
> 24060 Chiuduno - BG
> Phone: +39.035.839435
> Mobile: +39.348.3515786
> Fax: +39.030.5100306
> .-----------------------------.
> Web : www.p-soft.biz
> EMail: f.codebue@...