Solved

SQL: Add counter into View results

Posted on 2008-10-30
8
1,270 Views
Last Modified: 2010-04-21
I have an exisiting view that is called by an application. I am looking to add an incrementing counter to the output. The counter should be reset each time the view is called, and increment for each row of results when run.

Can someone give me push in the right direction how I would do this.

Thanks
0
Comment
Question by:JDCam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22842219
try to use the ROW_NUMBER() function in the view query.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22842292
An additional "push" would be


select row_number() over (order by Some_field_or_fields_in_your_view) rn, *
from Yourview
0
 

Author Comment

by:JDCam
ID: 22842429
Ok Great,
give me a chance to test it out
Thanks
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

Author Comment

by:JDCam
ID: 22842810
here is a snipit what I have...

SELECT Orders.Order_ID, ROW_NUMBER() over(Order by MO.MU_ID) RowNbr, Orders.Ship_To_Customer_Name,......

but get the result..
'ROW_NUMBER' is not a recognized function name.

is this not a standard function ??
0
 

Author Comment

by:JDCam
ID: 22842832
I guess it is important to add the DB is on SQL 2000 (sorry). I dont see this function there. Is there something comparable I can use ??
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22843019
row_number() is a SQL 2005+ function.  You posted the question int the SQL Server 2005 zone and not the MS SQL Server Zone.  You really can't do this from a view.  You would have to do it through a procedure that inserts into a temp table containing an identity column.
0
 

Author Closing Comment

by:JDCam
ID: 31511712
Thanks Brandon,
Sorry about the confusion. I use 2005 Mgr Studio on my desktop, but this particualar DB is still in 2000.  I will try as you suggest
0
 

Author Comment

by:JDCam
ID: 22843326
I will ask for additional help with this suggestion under a new question. (and properly categorized)
thanks.
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question