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 |
|
ArpitNarula
Starting Member
16 Posts |
Posted - 2011-03-08 : 07:30:25
|
| Hi guys,Below is the scenerio.Table A:system name A c A d A e B c B d B e need output in another table as system name GrpidA c 1A d 2A e 3B c 1B d 2B e 3 Can the groupid be auto generated Thanks in advance. |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2011-03-08 : 07:37:02
|
| while creating the Grpid column make it identity column. |
 |
|
|
ArpitNarula
Starting Member
16 Posts |
Posted - 2011-03-08 : 07:47:34
|
quote: Originally posted by ahmeds08 while creating the Grpid column make it identity column.
I beleive that will give the output as:system name GrpidA c 1A d 2A e 3B c 4B d 5B e 6Though I need...system name GrpidA c 1A d 2A e 3B c 1B d 2B e 3 |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-03-08 : 09:44:29
|
declare @Table_A table ([system] varchar(255), [name] varchar(255))insert @Table_Aselect 'A', 'c' union allselect 'A', 'd' union all select 'A', 'e' union all select 'B', 'c' union all select 'B', 'd' union all select 'B', 'e'select * from @Table_Aselect[system],[name],row_number() over (partition by [system] order by [name] asc) as Grpfrom @Table_A No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|