Question : T-SQL while loop

I am trying to re-organise some data using T-SQL and i have hit a bit of a brick wall. The data i have is in the following format:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
d id	r id
1	1
1	2
11	7
11	39
11	83
11	84
11	85
11	124
11	203
12	112
13	2
15	111
16	124
17	124
18	5
18	124
20	6
20	124
21	30
21	111
21	216
22	25
22	203
25	8
25	9
25	35
26	11
26	22
26	110
26	111
26	124
27	13
28	14
28	15
29	203
30	296

I am trying to write a query which will present the results in the following format:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
d id	r id
1	1,2
11	7,39,83,84,85,124,203
23	112
13	2
15	111
16	124
17	124
18	5,124
20	6,124
21	30,111,216


I think i need to select distinct d id's and then match on r id in some way but i am going round in circles!

Any help greatly apprciated!

Cheers

Answer : T-SQL while loop

Random Solutions  
 
programming4us programming4us