Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


arrange data for a report


arrange data for a report

Author
Message
slatinsky
slatinsky
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 187
Hello, I seem to be having a problem arranging my data in a way that can be utilized by a specific report

To simplify, after all the processing I end up with a table of column pairs (should not be more than a hundred records at most) that will look like so: (SQL Server 2005)


CREATE TABLE Links(
LinkID INT NOT NULL IDENTITY(1,1)
CONSTRAINT PK_Links_linkID PRIMARY KEY (LinkID),
Col1 INT NOT NULL,
Col2 INT NOT NULL
)

INSERT INTO Links (Col1, Col2)
SELECT 1,2
UNION ALL
SELECT 1,3
UNION ALL
SELECT 2,4
UNION ALL
SELECT 5, 3
UNION ALL
SELECT 3,2
UNION ALL
SELECT 7, 8
UNION ALL
SELECT 6,7
UNION ALL
SELECT 4, 1
UNION ALL
SELECT 1, 4



I need to write a select that will rearrange
the values in this table so that all the relationships between the 2 columns are presented
in a way that col1 contains the minimum value of the relationship and all others belong to this minimum value

Like so:

Col1 Col2
1 2
1 3
1 4
1 5
6 7
6 8

I was trying to use the recursive CTEs but did not succeed - I am hopeful there is a decent way of doing this - I would hate to use any kind of "row by row" approach

Thank you
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search