|
cvipin
Yak Posting Veteran
51 Posts |
Posted - 2010-03-01 : 14:23:55
|
| Hi,I need to write a query to get mentioned output. The test data is as below: Can you help..declare @test table (effective_date datetime, expiration_date datetime, product varchar(5), rate decimal(10, 4))Insert into @test values ('02/26/2010 8:00:00','02/27/2010 7:59:59','P1', 4.0000 )Insert into @test values ('02/26/2010 8:00:00','02/27/2010 7:59:59','P2', 4.1000 )Insert into @test values ('02/26/2010 8:00:00','02/27/2010 7:59:59','P3', 4.1500 )Insert into @test values ('02/26/2010 8:00:00','02/27/2010 7:59:59','P4', 4.1800 )Insert into @test values ('02/27/2010 8:00:00','02/28/2010 7:59:59','P1', 4.0100 )Insert into @test values ('02/27/2010 8:00:00','02/28/2010 7:59:59','P2', 4.1200 )Insert into @test values ('02/27/2010 8:00:00','02/28/2010 7:59:59','P3', 4.1550 )Insert into @test values ('02/27/2010 8:00:00','02/28/2010 7:59:59','P4', 4.1900 )Insert into @test values ('02/28/2010 8:00:00','03/01/2010 7:59:59','P1', 4.0100 )Insert into @test values ('02/28/2010 8:00:00','03/01/2010 7:59:59','P3', 4.1550 )Insert into @test values ('02/28/2010 8:00:00','03/01/2010 7:59:59','P4', 4.1900 )I need to select data for a data, '2/28/2010 9:15:25'. This date should be between effective_date and expiration_dateI need ouput as following: (P2 is also selected which is latest available rate)effective_date expiration_date product rate2010-02-28 08:00:00.000 2010-03-01 07:59:59.000 P1 4.01002010-02-27 08:00:00.000 2010-02-28 07:59:59.000 P2 4.12002010-02-28 08:00:00.000 2010-03-01 07:59:59.000 P3 4.15502010-02-28 08:00:00.000 2010-03-01 07:59:59.000 P4 4.1900ThanksVipin |
|