sql select statement counting the results

Posted on 2009-04-19
Last Modified: 2012-05-06
i am using sql server 2000. every time i am executing a select statement (f.e) select fielda, fieldb from table_a results come as follwing
a1 a2
b1 b2
c1 c2
d1 d2
..  ...

how can i create a column which will contains a increment by 1 counter. the select in this case should return

1  a1 a2
2  b1 b2
3  c1 c2
4  d1 d2
Question by:basilhs_s
    LVL 8

    Expert Comment

    You should be able to use the ROW_NUMBER function:

    Author Comment

    row_number is not supported in sql server 2000
    LVL 8

    Accepted Solution

    Yes sorry, I noticed that as soon as I posted it.
    You will need to do a workaround using a temp table with an identity column, an example can be found here:

    Author Closing Comment

    perfect answer for two reason. i saw how we count rows in sql server 2000 and since we are qoing to upgrade to sql sever 2008 soon i learned how i can use the row_counter() function there.. thanks very much

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now