Hi guys, and thanks for your interest in this puzzle :)
some notes below to clarify...
-------------------------------------------------------------------------=
-------
[quoted text, click to view] "Ed Murphy" <emurphy42@socal.rr.com> wrote in message =
news:KXxbh.35291$Fg.20663@tornado.socal.rr.com...
> Uri Dimant wrote:
>=20
>> If I understood you properly
>> =20
>> DECLARE @MaxWidth Integer
>> SET @MaxWidth =3D 240
>> SELECT [ImageID], [ImageWidth], [ImageBLOB], FROM [tblImages]
>> WHERE [ImageWidth]<@MaxWidth=20
>=20
> That applies the limit to each row individually. He wants to apply =
the
> limit to a running total of rows so far.
>=20
> Problem: the order of selecting rows hasn't been specified.=20
-------------------------------------------------------------------------=
-------
ok, I thought id try and strip it down to its bare essentials, but i =
perhaps should have mentioned...
I am SELECTing * FROM (SELECT TOP @ImageQty FROM tblImages ORDER BY =
NEWID() ) AS [ImageTable] ORDER BY [ImageWidth];
So i can ask for 5 images chosen at random and sorted by width.
The trouble is, that some images are panoramic, and up to 9 times wider =
than standard pics. Other shots are portait, and therefore a lot =
narrower. This causes display anomolies in the resulting html :(
if maxwidth=3D600
image1 could be 500 - running total=3D(500)
image2 could be 50 - (500+50=3D550, no fail)
image3 could be 75 - (550+75=3D625) Failcount =3D 1, try again 4 more =
times
image4 could be 250 - (550+250=3D800) Failcount =3D 2, try again 3 more =
times
image5 could be 50 - (550+50=3D600, no fail (600 is not > 600 ;))
image6 could be 75 - (600+75=3D675) Failcount =3D 3, try again 2 more =
times
image6 could be 75 - (600+500=3D1100) Failcount =3D 4, try again 1 more =
times
image6 could be 75 - (600+250=3D850) Failcount =3D 5, stop.
So, requesting a FINITE qty of images will not meet the needs of the =
goal.
The goal is: to get as many pictures, as close to a total width of 600 =
as possible. (without causing server meltdown, of course ;)
-------------------------------------------------------------------------=
-------
[quoted text, click to view] > (Insert standard Celko "rows vs. records" rant here.)
-------------------------------------------------------------------------=
-------
I'd like to know more about that... although, now that I have asked, I =
may live to regret it.
-------------------------------------------------------------------------=
-------
[quoted text, click to view] > If the intention is to
> select rows in ORDER BY ImageID order, then the running-total decision
> logic would work as follows.
>=20
> 1) Select ImageID 1, its ImageWidth is 60, the running total is 60.
> 2) Select ImageID 2, its ImageWidth is 60, the running total is
> 60+60=3D120.
> 3) Select ImageID 3, its ImageWidth is 120, the running total is
> 60+60+120=3D240.
> 4) Select ImageID 4, its ImageWidth is 200, the running total is
> 60+60+120+200=3D440.
>=20
> The running total has now exceeded 240, so stop selecting rows. But
> here's another problem: the description of the goal says to stop
> right away, but the pseudocode says to select five more rows and
> then stop.
-------------------------------------------------------------------------=
-------
Get five more, each time checking to see if we can squeeze it in to the =
remaining value.=20
After that, give up, to conserve server resources.
=20
-------------------------------------------------------------------------=
-------
[quoted text, click to view] > Googling (SQL "running total") turns this up as the first hit:
>=20
>
http://www.sqlteam.com/item.asp?ItemID=3D3856 >=20
> which gives three solutions, one that uses cursors and two that
> don't, and says (with some annoyance) that the cursor solution
> was an order of magnitude faster in speed tests (but, as usual,
> involves a longer block of code).
-------------------------------------------------------------------------=
-------
i'm looking into that...
once again,
thanks for your interest