Subject Re: RESTARTED [firebird-support] SELECT ... WHERE ... BETWEEN using TIMESTAMP felds
Author Helen Borrie
At 11:25 PM 20/04/2009, you 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?

Do you mean you don't want the first two lines?

>Any idea?

Dimitry didn't manage to demist your spectacles...so let's try again.

Select
Art.DATA_ORA,
...
from lsv, art
where
LSV.DATA_ORA between ....

Your search criterion (on LSV.DATA_ORA) has no effect on the DATA_ORA field in ART. If you want to exclude records on the basis of the value of ART.DATA_ORA then include a search criterion to do that!

(And fix up your inner join and order by syntaxes! The first because it is outdated and messy, the second because it's wrong.)

./hb