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 |
|
tjwent69
Starting Member
30 Posts |
Posted - 2009-11-27 : 09:56:05
|
| I am trying to simply display a counter for the rows I find.Basically I have an item, I have item discounts. I want to display the item and all of the discounts but I want each returned row of discounts to have a row count. I can do this in reporting services but I want to do it in t-sql. I have read through @@rowcount, cursors, while loops in BOL and Forums and they all seem to complicated or not quite right. Typically I don't know the 'keyword' to find what I want to do. Select '1234',27.00,29.99unionSelect '1234',30.00,39.99unionSelect '1234',40.00,99.99unionSelect '2345',27.00,99.99unionSelect '3456',30.00,39.99unionSelect '3456',40.00,49.99unionSelect '3456',50.00,59.99unionSelect '3456',60.00,59.99unionSelect '3456',70.00,69.99unionSelect '3456',80.00,79.99I want the above sample data to look like this.1 1234 27 29.992 1234 30 39.993 1234 40 99.991 2345 27 99.991 3456 30 39.992 3456 40 49.993 3456 50 59.994 3456 60 59.995 3456 70 69.996 3456 80 79.99 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-27 : 09:58:58
|
| Which version of SQL Server are you using?MadhivananFailing to plan is Planning to fail |
 |
|
|
tjwent69
Starting Member
30 Posts |
Posted - 2009-11-27 : 12:22:55
|
| 2005 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-28 : 01:18:55
|
| select row_number() over (partition by col1 order by col1) as row_count,* from your_tableMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|