November 5, 2003 at 11:24 am
No need for cursors if I understand the problem.
SELECT Currency, Value, Start_Date,
(SELECT MIN(Start_Date) - 1
FROM Csv
WHERE Currency = c.Currency
AND Start_Date > c.Start_Date) End_Date
FROM Csv c
--Jonathan
--Jonathan
November 5, 2003 at 12:41 pm
You could just calculate the value once it's in SQL by finding the row just before it (in terms of date) like this:
select
a.currency
, a.currdate 'current date'
, b.currdate 'last date'
from table a
inner join table b
on a.currency = b.currency
where b.currdate = ( select max( currdate)
from Table c
where c.currency = a.currency
and c.currdate < a.currdate
)
Steve Jones
http://www.sqlservercentral.com/columnists/sjones
The Best of SQL Server Central.com 2002 - http://www.sqlservercentral.com/bestof/
November 7, 2003 at 7:14 am
Thanks guys - works a treat!
Viewing 3 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply