Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. datedifference from two different tables

datedifference from two different tables

Scheduled Pinned Locked Moved Database
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    n_gchaitra
    wrote on last edited by
    #1

    Hi, I want to find the date difference of date1 and date2. But these two colums are present in different tables. I have used joins but not getting proper results because the no of rows i am getting is the cartesian product of the two tables. I am includeing two tables and the result i have got after using joins. Please tell the right way to do this. Tran_type Partno Description Transactiondate Quantity Rate Balqty --------- ------ ----------- ------------------- ------------ --------- ------- R ABC NULL 2005-01-01 00:00:00 15.0 20.0 15.0 R ABC NULL 2005-04-02 00:00:00 15.0 30.0 15.0 R ABC NULL 2005-09-01 00:00:00 50.0 30.0 50.0 (3 row(s) affected) Tran_type Partno Description Transactiondate Quantity Rate Balqty ---------- ------ ----------- ------------------- ----------- --------- -------- S ABC NULL 2005-06-03 00:00:00 5.0 25.0 NULL S ABC NULL 2005-07-01 00:00:00 5.0 10.0 NULL S ABC NULL 2006-06-01 00:00:00 15.0 50.0 NULL (3 row(s) affected) tran_type transactiondate transactiondate tran_type Date diff --------- --------------------------- --------------------------- ---------- ----------- R 2005-01-01 00:00:00 2005-06-03 00:00:00 S 153 R 2005-04-02 00:00:00 2005-06-03 00:00:00 S 62 R 2005-09-01 00:00:00 2005-06-03 00:00:00 S -90 R 2005-01-01 00:00:00 2005-07-01 00:00:00 S 181 R 2005-04-02 00:00:00 2005-07-01 00:00:00 S 90 R 2005-09-01 00:00:00 2005-07-01 00:00:00 S -62 R 2005-01-01 00:00:00 2006-06-01 00:00:00 S 516 R 2005-04-02 00:00:00 2006-06-01 00:00:00 S 425 R 2005-09-01 00:00:00 2006-06-01 00:00:00 S 273 (9 row(s) affected)

    Chaitra N

    N 1 Reply Last reply
    0
    • N n_gchaitra

      Hi, I want to find the date difference of date1 and date2. But these two colums are present in different tables. I have used joins but not getting proper results because the no of rows i am getting is the cartesian product of the two tables. I am includeing two tables and the result i have got after using joins. Please tell the right way to do this. Tran_type Partno Description Transactiondate Quantity Rate Balqty --------- ------ ----------- ------------------- ------------ --------- ------- R ABC NULL 2005-01-01 00:00:00 15.0 20.0 15.0 R ABC NULL 2005-04-02 00:00:00 15.0 30.0 15.0 R ABC NULL 2005-09-01 00:00:00 50.0 30.0 50.0 (3 row(s) affected) Tran_type Partno Description Transactiondate Quantity Rate Balqty ---------- ------ ----------- ------------------- ----------- --------- -------- S ABC NULL 2005-06-03 00:00:00 5.0 25.0 NULL S ABC NULL 2005-07-01 00:00:00 5.0 10.0 NULL S ABC NULL 2006-06-01 00:00:00 15.0 50.0 NULL (3 row(s) affected) tran_type transactiondate transactiondate tran_type Date diff --------- --------------------------- --------------------------- ---------- ----------- R 2005-01-01 00:00:00 2005-06-03 00:00:00 S 153 R 2005-04-02 00:00:00 2005-06-03 00:00:00 S 62 R 2005-09-01 00:00:00 2005-06-03 00:00:00 S -90 R 2005-01-01 00:00:00 2005-07-01 00:00:00 S 181 R 2005-04-02 00:00:00 2005-07-01 00:00:00 S 90 R 2005-09-01 00:00:00 2005-07-01 00:00:00 S -62 R 2005-01-01 00:00:00 2006-06-01 00:00:00 S 516 R 2005-04-02 00:00:00 2006-06-01 00:00:00 S 425 R 2005-09-01 00:00:00 2006-06-01 00:00:00 S 273 (9 row(s) affected)

      Chaitra N

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Could you show the query ?


      My Website | Ask smart questions

      N 1 Reply Last reply
      0
      • N N a v a n e e t h

        Could you show the query ?


        My Website | Ask smart questions

        N Offline
        N Offline
        n_gchaitra
        wrote on last edited by
        #3

        select 'Difference in Date'=datediff(dd,r.rdate,i.idate) from receive r,issue i where r.partno=i.partno

        Chaitra N

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups