"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> skrev i
meddelandet news:uI**************@TK2MSFTNGP12.phx.gbl...
Andreas Håkansson wrote:
Now I will try to round it of to keep the lenght down. Basiclly what I
want to do it get out each unique (distinct) travel route of all packages
in a given direction.
Well, some sample would be helpful here.
Ok I will try to provide an example. The problem is that there are so many
variations which I could illustrate in an example, although the main concept
is the same for each situation.
Lets back up and have a look at the XML which looks like this.
<Package>
<Id>12345</Id>
<Price>100</Price>
<Catagory>AAA</Catagory>
<Routs>
<Route>
<City1>A</City1>
<City2>B</City2>
<DateTime1>10:00</DateTime1>
<DateTime2>11:15</DateTime2>
<Direction>1</Direction>
</Route>
<Route>
<City1>B</City1>
<City2>C</City2>
<DateTime1>12:00</DateTime1>
<DateTime2>14:00</DateTime2>
<Direction>1</Direction>
</Route>
<Route>
<City1>C</City1>
<City2>A</City2>
<DateTime1>07:00</DateTime1>
<DateTime2>10:00</DateTime2>
<Direction>2</Direction>
</Route>
</Routs>
</Package>
<Package>
<Id>12346</Id>
<Price>100</Price>
<Catagory>AAA</Catagory>
<Routs>
<Route>
<City1>A</City1>
<City2>B</City2>
<DateTime1>10:00</DateTime1>
<DateTime2>11:15</DateTime2>
<Direction>1</Direction>
</Route>
<Route>
<City1>B</City1>
<City2>C</City2>
<DateTime1>12:00</DateTime1>
<DateTime2>14:00</DateTime2>
<Direction>1</Direction>
</Route>
<Route>
<City1>C</City1>
<City2>A</City2>
<DateTime1>07:00</DateTime1>
<DateTime2>10:00</DateTime2>
<Direction>2</Direction>
</Route>
</Routs>
</Package>
<Package>
<Id>12346</Id>
<Price>100</Price>
<Catagory>AAA</Catagory>
<Routs>
<Route>
<City1>A</City1>
<City2>B</City2>
<DateTime1>16:00</DateTime1>
<DateTime2>17:15</DateTime2>
<Direction>1</Direction>
</Route>
<Route>
<City1>B</City1>
<City2>C</City2>
<DateTime1>08:00</DateTime1>
<DateTime2>10:00</DateTime2>
<Direction>2</Direction>
</Route>
<Route>
<City1>C</City1>
<City2>A</City2>
<DateTime1>11:00</DateTime1>
<DateTime2>12:30</DateTime2>
<Direction>2</Direction>
</Route>
</Routs>
</Package>
<Package>
<Id>12348</Id>
<Price>150</Price>
<Catagory>AAA</Catagory>
<Routs>
<Route>
<City1>A</City1>
<City2>B</City2>
<DateTime1>10:00</DateTime1>
<DateTime2>11:15</DateTime2>
<Direction>1</Direction>
</Route>
<Route>
<City1>B</City1>
<City2>C</City2>
<DateTime1>12:00</DateTime1>
<DateTime2>14:00</DateTime2>
<Direction>1</Direction>
</Route>
<Route>
<City1>C</City1>
<City2>A</City2>
<DateTime1>07:00</DateTime1>
<DateTime2>10:00</DateTime2>
<Direction>2</Direction>
</Route>
</Routs>
</Package>
We have a list of packages - each packade is identified by an Id and
also stores the Price and Catagory of the package. The route for which
the package was shipped to it's location and back again is stored together
with the package.
The first level of grouping is by PRICE and CAtAGORY. This means that
the three first packages are grouped since they share the same price and
catagory. So far I have no problem.
It is the next grouping/filtering/selection level which is the source of my
problems :) Once the first level of grouping has been applied, I want to
get all of the unique combinations of Route items for the packages which
was grouped in level 1.
So If we only look at the first 3 packages and only on the routes with
direction 1 (since it will be the same for Direction 2 - I want to include
them
as well but for simplicity I think I can omitt them in this example, just
keep
in mind that direction 2 should be included as well although only compared
with other direction 2 routes in the same group) we have
<City1>A</City1>
<City2>B</City2>
<DateTime1>10:00</DateTime1>
<DateTime2>11:15</DateTime2>
<City1>B</City1>
<City2>C</City2>
<DateTime1>12:00</DateTime1>
<DateTime2>14:00</DateTime2>
<City1>A</City1>
<City2>B</City2>
<DateTime1>10:00</DateTime1>
<DateTime2>11:15</DateTime2>
<City1>B</City1>
<City2>C</City2>
<DateTime1>12:00</DateTime1>
<DateTime2>14:00</DateTime2>
<City1>A</City1>
<City2>B</City2>
<DateTime1>16:00</DateTime1>
<DateTime2>17:15</DateTime2>
Which should be shortened to the distinct routes.
A B 10:00 11:15
B C 12:00 14:00
A B 16:00 17:15
Now Imagine we also have the same information for Direction 2. What I have a
need
for in my application is to hav ethe user select one of the DISTINCT routes
for direction 1
and one of the DISTINCT routes for direction 2. When he/she has done this I
need to match
them with the package/packages which contains this pair of routes. This
means I will need to
store the Package ID with the transformed routes.
So still only illustrating with the help of Direction 1 routes I need
something like this to be
stored with the distinct routes for the first level of grouping.
<Routes>
<Route>
<City1>A</City1>
<City2>B</City2>
<DateTime1>10:00</DateTime1>
<DateTime2>11:15</DateTime2>
<Packages>
<Package>12345</Package>
<Package>12346</Package>
</Packages>
</Route>
<Route>
<City1>B</City1>
<City2>C</City2>
<DateTime1>12:00</DateTime1>
<DateTime2>14:00</DateTime2>
<Packages>
<Package>12345</Package>
<Package>12346</Package>
</Packages>
</Route>
<Route>
<City1>A</City1>
<City2>B</City2>
<DateTime1>16:00</DateTime1>
<DateTime2>17:15</DateTime2>
<Packages>
<Package>12347</Package>
</Packages>
</Route>
</Routes>
So what I have done (in theory ;) is first group by PRICE and CATAGORY. Then
I
select the DISTINCT routes withing each of the groupes (in my examples I
have only
illustrated from within one group) and store information with each route
about which
packages used that route.
If I get this far then I have no problem doing the reverse lookup which is
when I go from
Direction 1 & 2 pair of routes -> one or many packages which contains the
route pair in
question.
Maybe it is easier to think of it like flight itineraries. You want to fly
from A to B and get
a bounch of Itineraries, each detailing which route if will fly (stops and
time for each stop).
You start of by grouping them by thier Price and Carrier. Then you precede
to get each of
the unique routes for the trip from A to B. You then decide I want to fly
from point A to B
at Time1 and Time2 .and then back from B to A at Time1 and Time2. Once you
have decided
this you look up which Itinerary contains the desired route pair and get
it's ID (this last part
is what I described with the Packages node in the last XML text.
Hope this made it a bit more clear what I want to do? I'm having a really
hard time explaining
this in a clear way! ;)
//Andreas