learnsql123
Starting Member
23 Posts |
Posted - 2012-11-06 : 12:07:06
|
Here is my data:Drop table #TempCREATE TABLE #Temp(ID int, Proj varchar(5), lkey int, akey int, Gname varchar(5), pnum varchar(12)) Insert into #TempValues(1, 'Proj1',988,4481,'aaa','12-1'),(2, 'Proj1',757,4482,'bbb','12-1'),(3, 'Proj1',617,4173,'ccc','12-3'),(4, 'Proj1',493,4175,'ddd','12-3'),(5, 'Proj1',404,4174,'ddd','12-3'),(6, 'Proj1',284,4176,'eee','13-1'),(7, 'Proj1',369,4177,'fff','14-3'),(8, 'Proj1',440,4178,'ggg','15-6')Select * from #TempI need to assign a groupNums as follows:If they have same pNum value they get the same GropuNumand all GroupNums will be sequential numbersSo the end result will be as follows:ID Proj lkey akey Gname pnum GroupNum1 Proj1 988 4481 aaa 12-1 12 Proj1 757 4482 bbb 12-1 13 Proj1 617 4173 ccc 12-3 24 Proj1 493 4175 ddd 12-3 25 Proj1 404 4174 ddd 12-3 26 Proj1 284 4176 eee 13-1 37 Proj1 369 4177 fff 14-3 48 Proj1 440 4178 ggg 15-6 5How can I use PartitionBy or OrderBy clause to get this result?Thanks for helping. |
|