Results 1 to 4 of 4

Thread: Sql query for Date function.

  1. #1
    Join Date
    Nov 2010
    Posts
    34

    Sql query for Date function.

    Hey, I'm trying to run a SQL query but can't uncover any records when tiresome to select a certain date. Here's the query:
    SELECT fld 1, fld 2, date,
    FROM table 1
    WHERE date = '01-SEP-2010'
    I'm getting no results. The date field is formatted like this:
    2010-SEP-02 10:01:04

    Another query is:
    SELECT fld 1, fld 2, date,
    FROM table 1
    WHERE date >= '01-SEP-2010' & date <= '01-DEC-2010'
    I'm wonder that the trouble may have something to do with the date
    field containing both the date.

  2. #2
    Join Date
    May 2009
    Posts
    511

    Re: Sql query for Date function.

    You are building the mistake of comparing a string field to a date field. Compare a date to a date as . '01-SEP-10'' is a string, date is a date. Try this one:
    SELECT fld 1, fld2, date,
    FROM table 1
    WHERE date >=to_date('01-SEP-10','dd-mmm-yy') and date<= to_date('01-DEC-10','dd-mmm-yy');

    You should actually use 4 digit years if not you really mean the year 2. So
    it should be:
    SELECT fld 1, fld2, date,
    FROM table 1
    WHERE date >=to_date('01-SEP-2010’,'dd-mmm-yyyy') and date <= to_date('01-DEC-2010','dd-mmm-yyyy');

  3. #3
    Join Date
    May 2009
    Posts
    543

    Re: Sql query for Date function.

    If you want fields from two tables where one field is common in table. So the date function for '01-SEP-10'' is a string, date is a date. Try this one:
    SELECT s.fld 1, m.fld2,m.fld 3, date,
    FROM table 1 as s, table 2 as m
    WHERE m.fld 3 =s.fld 3 and date >=to_date('01-SEP-10','dd-mmm-yy') and date<= to_date('01-DEC-10','dd-mmm-yy');
    Last edited by Jacques25; 17-11-2010 at 12:19 AM.

  4. #4
    Join Date
    Apr 2009
    Posts
    569

    Re: Sql query for Date function.

    You can also use different query for fields from two tables where one field is same in two tables. So the date function for '01-SEP-10''. Check out this one:
    SELECT t.fld 1, f.fld2,f.fld 3, date,
    FROM table 1 as t, table 2 as f
    WHERE t.fld 3 =f.fld 3 and date between '01-SEP-10'and '01-DEC-10';

    You should actually use 4 digit years if not you really mean the year 2. So it look like this:
    SELECT t.fld 1, f.fld2,f.fld 3, date,
    FROM table 1 as t, table 2 as f
    WHERE t.fld 3 =f.fld 3 and date between '01-SEP-2010'and '01-DEC-2010';

Similar Threads

  1. Query with Date in java
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 03:55 AM
  2. Query in function getIfModifiedSince()
    By New ID in forum Software Development
    Replies: 5
    Last Post: 18-01-2010, 01:09 PM
  3. Date function in PHP
    By RobertoOrtiz in forum Software Development
    Replies: 2
    Last Post: 05-05-2009, 07:54 PM
  4. Excel function calculations used in MS Access query
    By akbar in forum MS Office Support
    Replies: 1
    Last Post: 23-05-2008, 08:52 PM
  5. Windows 2000 Server query to disable date
    By Saphire in forum Window 2000 Help
    Replies: 2
    Last Post: 09-11-2007, 08:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,710,023.40600 seconds with 17 queries