October 23, 2008 at 3:15 pm
sognibene (10/23/2008)
... I also had to change r1.[Date] to D.[Date] in the final select.
Heh, you are correct. That was a logical error on my part.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
December 23, 2008 at 6:07 pm
Sognibene,
Well, this one certainly slipped through the cracks... are you all set?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 24, 2008 at 9:11 am
Jeff, I lost quite a few brain cells on this one, as it was just a bit over my head, and would be interested to see your solution, using your tally table no doubt. If not interested, have a happy holiday.
Greg
_________________________________________________________________________________________________
The glass is at one half capacity: nothing more, nothing less.
December 24, 2008 at 9:43 am
Greg Snidow (12/24/2008)
Jeff, I lost quite a few brain cells on this one, as it was just a bit over my head, and would be interested to see your solution, using your tally table no doubt. If not interested, have a happy holiday.
If he is interested, can he still have a happy holiday? :hehe:
Happy Holidays Greg. 😛
December 24, 2008 at 11:51 am
What caught my eye was the following...
sognibene (10/23/2008)
I will post what I am able to get working.
That seemed to leave the problem up in the air. I wanted to know if sognibene was actually able to get something working and, if so, what it was. The reason is because I believe it's a mistake to do this as a view for performance reasons... why recalculate the same thing over and over and over? I think Seth's suggestion would be the best route to go...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 24, 2008 at 2:14 pm
Yes, but any View solution can be converted to a pre-aggregated solution just by doing: SELECT * INTO PreAggTable FROM MyViewSolution
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
December 24, 2008 at 5:04 pm
Sure it can... but then why spend all those brain cells trying to do it in a single query when a proc can do the same thing and maybe a bit faster?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 24, 2008 at 7:47 pm
Brain Cells? You have Brain Cells?!? How do I get some of those??
😛
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
December 25, 2008 at 9:41 am
You're supposed to ask for them BEFORE Christmas! 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
December 25, 2008 at 10:30 am
Brain Cells? You have Brain Cells?!? How do I get some of those??
😛 😛
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
December 25, 2008 at 12:09 pm
Heh... only 365 brain cell shopping days left...
--Jeff Moden
Change is inevitable... Change for the better is not.
December 29, 2008 at 2:05 pm
I'll admit to not reading all the posted solutions, so maybe mine is redundant. It just continually propagates the last defined rate data forward until it is changed. The only thing you need to know about my setup is that my Tally table starts at 0 instead of 1.
declare @Rates table(
FromCurr char(3),
ToCurr char(3),
RateDate datetime,
Rate numeric(38,16),
Factor int
);
declare @FromDate datetime,
@ToDate datetime;
select @FromDate = '2008-10-15',
@ToDate = '2008-10-21';
-- INSERT SAMPLE DATA
Insert @Rates
(FromCurr, ToCurr, RateDate, Rate, Factor)
select 'USD', 'IDR', '10/16/2008', 9818.0, -1 union all
select 'USD', 'IDR', '10/20/2008', 9807.5, -1 union all
select 'USD', 'AUD', '10/16/2008', 0.6617, 1 union all
select 'USD', 'AUD', '10/20/2008', 0.68895, 1 union all
select 'USD', 'XYZ', '10/18/2008', 98.0, -1;
select x.CurrentDate, r.RateDate, r.FromCurr, r.ToCurr, r.Rate, r.Factor
from(
select DateAdd( dd, ZN, @FromDate )
from dbo.Tally
where DateAdd( dd, ZN, @FromDate ) between @FromDate and @ToDate
) x (CurrentDate)
join @Rates r
on r.RateDate = (
select Max( r1.RateDate )
from @Rates r1
where r1.RateDate <= x.CurrentDate
and r1.FromCurr = r.FromCurr
and r1.ToCurr = r.ToCurr
)
order by r.ToCurr, x.CurrentDate;
Tomm Carr
--
Version Normal Form -- http://groups.google.com/group/vrdbms
Viewing 12 posts - 16 through 26 (of 26 total)
You must be logged in to reply to this topic. Login to reply