Results 1 to 4 of 4

Thread: Help! join with dates

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2008
    Posts
    6

    Help! join with dates

    After a lot of searching and trying I put my question here:

    I have 2 tables (data1108 & data1208)
    both tables have the same fields: date(text), amount(number) and type(number)

    Now I want to have all records with the following criteria:

    Date must be between date1 and date2, amount must be 5 and type must be 3.

    The SQL for 1 table looks like this:
    "SELECT * FROM data1108 WHERE amount = 5 AND type = 3 AND CLng(cdate(date)) BETWEEN CLng(CDate(date1)) AND CLng(CDate(date2))"

    This works nice but now I want this from the 2 tables...which I can not figure out.

    Help would be highly appreciated!

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Help! join with dates

    "SELECT * FROM data1108 WHERE amount = 5 AND type = 3 AND CLng(cdate(date)) BETWEEN CLng(CDate(date1)) AND CLng(CDate(date2)) UNION SELECT * FROM data1208 WHERE amount = 5 AND type = 3 AND CLng(cdate(date)) BETWEEN CLng(CDate(date1)) AND CLng(CDate(date2))"

    This should return all the values from both tables. Might I ask though, why you have more than one table with the same columns? And why the numbers in the table name after "data" look like dates?

    Also moved to Database Development forum.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Help! join with dates

    This would be a database question, but anyway, what your after is a union query.

    Heres a link: http://www.w3schools.com/sql/sql_union.asp

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Help! join with dates

    Why are you converting a date to a Long?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width