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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Assign a column of natural numbers to sorted table

Author  Topic 

lovecherry
Starting Member

3 Posts

Posted - 2006-12-08 : 23:19:58
Hi, does anybody know how to assign a column of natural numbers to a sorted table? I mean, I have sorted the table, now I want to EXPLICITLY show on the table that "this is #1, this is #2..." Can anybody help? Thanks!

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-12-08 : 23:22:02
Add an IDENTITY column to the table.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

lovecherry
Starting Member

3 Posts

Posted - 2006-12-08 : 23:31:42
Actually what I meant to do is to get quintiles. In order to do that, I do cumulative sum first, and then just SELECT CASE. The way I do cumulative sum is like this, but I realized it only worked when I have a column of natural number with my descendingly sorted sales.

SELECT a.DayCount, a.Sales, SUM(b.Sales) AS RunningTotal
FROM Sales a CROSS JOIN Sales b ON b.DayCount <= a.DayCount
GROUP BY a.DayCount , a.Sales
ORDER BY a.DayCount , a.Sales
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-09 : 02:49:27

1 Are you tring to find Running Total? If you use front end application, you can do easily there
2 To do in sql is ineffecient and you need to have unique key for that
3 If not, You can copy the data to temp table that has identity column and do Running Total

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -