Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Matching Two Tables on Date field

Author  Topic 

praveeri
Starting Member

5 Posts

Posted - 2010-06-26 : 05:40:51
I have two tables

Tabl1

Date Product Price WithEfft


Table2

Date Product Price qty value

Price in table2 is fetched from table1

date column in table1 will always not equal to date column in table2

I want to join both tables where date in table2 is greater than or equal to table1 and it should never be greater than the second occurance of the date in table1

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-26 : 06:36:07
It is always the same song.
We need table structure and sample data and wanted output.
Otherwise it is not easy to give a solution.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

praveeri
Starting Member

5 Posts

Posted - 2010-06-26 : 06:55:49
thanks fred here is the details


Table1
date product price withefft
01/06/2010 sss 500 01/06/2010
01/06/2010 ttt 625 01/06/2010
06/06/2010 sss 510 06/06/2010
06/06/2010 ttt 605 06/06/2010

Table2
Date product price qty value
01/06/2010 sss 500 2 1000
01/06/2010 sss 500 3 1500
01/06/2010 ttt 625 1 625
01/06/2010 ttt 625 1 625
02/06/2010 sss 500 1 500
02/06/2010 ttt 625 3 1875
05/06/2010 ttt 625 5 3125
06/06/2010 sss 510 5 2550

wanted result

Date product price qty value table1.date table1.product table1.price table1.witheffct
01/06/2010 sss 500 2 1000 01/06/2010 sss 500 01/06/2010
01/06/2010 sss 500 3 1500 01/06/2010 sss 500 01/06/2010
01/06/2010 ttt 625 1 625 01/06/2010 ttt 625 01/06/2010
01/06/2010 ttt 625 1 625 01/06/2010 ttt 625 01/06/2010
02/06/2010 sss 500 1 500 01/06/2010 sss 500 01/06/2010
02/06/2010 ttt 625 3 1875 01/06/2010 ttt 625 01/06/2010
05/06/2010 ttt 625 5 3125 01/06/2010 ttt 625 01/06/2010
06/06/2010 sss 510 5 2550 06/06/2010 sss 510 06/06/2010
Go to Top of Page
   

- Advertisement -