Actual price on this date
got a table with dates and prices.
Date Price 2012-01-01 25 2012-01-05 12 2012-01-10 10
Is there some function that allows me to find the current price where on '2012-01-07'? Without me, knowing about other dates.
Pseudoquery: select a price where currentprice ('2012-01-07')
Thank!
+3
source to share
3 answers
If you don't have the use of ROW_NUMBER () and want a general solution, then you need to join a subquery.
Get the date you want, then get the data for that date.
SELECT
*
FROM
yourTable
INNER JOIN
(
SELECT MAX(yourDate) AS maxDate FROM yourTable WHERE yourDate <= @dateParameter
)
AS lookup
ON yourTable.yourDate = lookup.maxDate
+1
source to share