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 |
|
marat
Yak Posting Veteran
85 Posts |
Posted - 2005-09-12 : 03:13:28
|
| Hi,I have a table A:id Letter1 a2 b3 b4 c5 b6 b7 b8 f9 e10 eI need to generate groups to get table Bid Letter Group1 a 12 b 23 b 24 c 35 b 46 b 47 b 48 f 59 e 610 e 6How I can get this result without using cursor?Thanks |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
|
|
marat
Yak Posting Veteran
85 Posts |
Posted - 2005-09-12 : 20:47:58
|
| ThanksI am going to look at it.Results - later |
 |
|
|
marat
Yak Posting Veteran
85 Posts |
Posted - 2005-09-13 : 07:27:12
|
| Hi Spirit1,After a few changes to the script you reffered, I got the following:create table SQLisFun(urn int Not Null,letter char(1) Not Null) GOinsert SQLisFunselect 1, 'a'union allselect 2, 'b'union allselect 3, 'b'union allselect 4, 'c'union allselect 5, 'b'union allselect 6, 'b'union allselect 7, 'b'union allselect 8, 'f'union allselect 9, 'e'union allselect 10, 'e'union allselect 11, 'e'union allselect 12, 'a'union allselect 13, 'a'union allselect 14, 'c'union allselect 15, 'c'select * from SQLisFunselect letter, grp, identity(int,1,1) as MasterGrp into SQLisFun_Groupsfrom(select urn, letter, (select isnull(max(urn),0) from SQLisFun Gwhere G.letter <> GC.letter and G.urn < GC.urn) as grp from SQLisFun GC) Dgroup by letter, grporder by grpselect G.urn,G.letter, MasterGrpfrom (select urn, letter, (select isnull(max(urn),0) from SQLisFun Gwhere G.letter <> GC.letter and G.urn < GC.urn) as grp from SQLisFun GC) Ginner join SQLisFun_Groups GGon G.letter = GG.letter and G.grp = GG.grpThanks |
 |
|
|
|
|
|
|
|