Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-SQL Matching Values or previous Values

$
0
0

Hi,

I'm wondering if someone can point me in the right direction for this particular query - using 2008R2.

I have a table that contains date, fruit, value and prices. The table only contains data for two fruit. What i want to find is the value of certain prices (0, 5, 10, 15)  for the date range. The kicker is, if no value exist for the price, then use the previous value.

So using the following

Date, Fruit, Value, Price

14/04 apple, 100, 0

14/04 orange, 101, 0

then it should return

14/04, 201, 0

but if there is no match, then it should use the previous value

14/04 apple, 25, 5

14/04 orange, 50, 4

then it should return

14/04 , 75, 5

I'm thinking a loop might be the way to go?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>