If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-03, 13:04
hmarm761 hmarm761 is offline
Registered User
 
Join Date: Jul 2003
Posts: 1
Exclamation query help

Hi, I'm not sure if my query is well done.

I need to select from a table the registers where the date of the field TIP_FECHA_FIN have 30+ days since sysdate. The TIP_FECHA_FIN is a DATE field.

I've tried with the following query.

select tip_fecha_fin from btdttip where tip_fecha_fin < (sysdate-30);

If the sysdate-30 is 14-JUN-03

I got the following result.

SQL> select tip_fecha_fin from btdttip where tip_fecha_fin < (sysdate-30);

TIP_FECHA
---------
01-JUN-03
13-JUN-03
14-JUN-03
20-JUN-03
20-JUN-03
20-JUN-03
19-JUN-03
30-JUN-03

8 rows selected.

What am I doing wrong? How can I fix my query? Please help me.
Reply With Quote
  #2 (permalink)  
Old 07-14-03, 14:19
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool

Try:

select tip_fecha_fin from btdttip where tip_fecha_fin < TRUNC(sysdate-30);
Reply With Quote
  #3 (permalink)  
Old 07-14-03, 18:13
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: query help

Quote:
Originally posted by hmarm761
Hi, I'm not sure if my query is well done.

I need to select from a table the registers where the date of the field TIP_FECHA_FIN have 30+ days since sysdate. The TIP_FECHA_FIN is a DATE field.

I've tried with the following query.

select tip_fecha_fin from btdttip where tip_fecha_fin < (sysdate-30);

If the sysdate-30 is 14-JUN-03

I got the following result.

SQL> select tip_fecha_fin from btdttip where tip_fecha_fin < (sysdate-30);

TIP_FECHA
---------
01-JUN-03
13-JUN-03
14-JUN-03
20-JUN-03
20-JUN-03
20-JUN-03
19-JUN-03
30-JUN-03

8 rows selected.

What am I doing wrong? How can I fix my query? Please help me.
I suspect that those dates are in 1903 not 2003. You should always use a 4-digit year to be sure of that:

alter session set nls_date_format='DD-MON-RRRR';

You can put that command in a file called login.sql or glogin.sql and have it run automatically every time you start SQL Plus.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On