Friday, March 23, 2012

Parent Child Tables

In our database we have a list of devices in a "Device" Table, each
having one or more IP's located in the "IP" Table linked through a
forein key on the DeviceID Column.

I would like to retrieve this information as Such

DeviceID IpAddress
1 10.0.0.1, 10.0.0.2, 10.0.0.3
2 ...
3
4
5
etc.

Is it possible to do that without using cursors? Through a query?"Mark" <markoueis@.hotmail.com> wrote in message
news:b1800bd3.0402231034.7facd986@.posting.google.c om...
> In our database we have a list of devices in a "Device" Table, each
> having one or more IP's located in the "IP" Table linked through a
> forein key on the DeviceID Column.
> I would like to retrieve this information as Such
> DeviceID IpAddress
> 1 10.0.0.1, 10.0.0.2, 10.0.0.3
> 2 ...
> 3
> 4
> 5
> etc.
> Is it possible to do that without using cursors? Through a query?

There are several ways to do this (see the link below for one solution) but
in general it's easier to do this in a client application - formatting data
for presentation shouldn't usually be done in SQL code.

http://www.aspfaq.com/show.asp?id=2279

Note that this solution cannot guarantee to sort the data in any particular
order (see the KB article referenced from the link), so if that is a
requirement then you will need to use a cursor or client code.

Simon

No comments:

Post a Comment