Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
lvirden
Starting Member
4 Posts |
Posted - 2012-02-14 : 10:59:41
|
I am trying to figure out how best to perform a query which draws data from two different tables, and in one of the tables, related data is in different rows. Here's my attempt at a really dumb example:There are 3 columns of interest* Logical.name from table cir* Related.cis from table cir (note this column contains one or mroe logical.name values, separated by control-M. These items are related in some way with the logical.name of the row.)* Subtype from table devThe report that I need should display Logical.name values, grouped by subtype, chaining through the related.cis fieldFor example, if the tables look liked thisTable: CirelationshipLogical.name related.cisA B E GB CC IDE F HF HG IH I JI KJKTable: deviceLogical.name SubtypeA Biz 1B C D Biz 2E F G H I J KL Then the desired report might be:Biz 1ABCEFGHIJKBiz 2DWhere the ordering in the report is not essentialNotice that if the output includes Biz 3 with nothing under it, that is fine. The main importance is that all logical.name's related through the related.cis are displayed, no matter how nested.While in theory there should NOT be circular relationships, I don't think there is anything in the system to prevent them.Obviously, if a circle exists, we don't want the items to repeat over and over.Is this doable from a select statement (as opposed to having to write code to dynamically generate various select statements and then parsing the results)?Thank you! |
|
|
|
|