Write SQL amazingly fast with SQL Prompt
Getting started with SSIS - Part 1: Introduction to SSIS
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.
Loading

Ask in the public forum

Ask your questions in a public forum

My Blog Posts

SQL Server Monitoring
  • Row Numbers

    I want to generate row numbers in SQL 2000, there is a great function in SQL 2005 and onwards to generate row number by a simple function, but i get stuck into this, is there anyways to generate row numbers in SQL Server 2000.

    poncho
    1186 · 0% · 9

7  Replies  

Subscribe to Notifications
  • 1 Note that if it is only for a display purpose show row numbers in the front end application

    2 You can use a temporary table with identity column

    SELECT identity(int,1,1) as row_num,* from #temp from your_table

    SELECT * from #temp order by Row_num

    Madhivanan
    3 · 34% · 5789
  • Thanks for your reply.

    but i want to generate row_numbers as in SQL 2005 as i have some calculation to do on data like i want to get the records from row numer=5.

    I heard about corelated queries but i am not able to figure it how?

    poncho
    1186 · 0% · 9
  • Similar to the previous answerer..

    SELECT  Identity(1,1)  as RowNumer,  *
    INTO  #tmpTable
    FROM yourtablename

    Then work with the #tmpTable for ur calculations

    karinloos
    65 · 3% · 588
  • -- Generate row numbers using a triangle join; must have a primary key and select and group by all columns

    select count(*) as RowNum, PrimaryKeyColumn, OtherColumn1, OtherColumn2, OtherColumnN

    from Table1 a

    join Table1 b on a.PrimaryKeyColumn >= b.PrimaryKeyColumn

    group by PrimaryKeyColumn, OtherColumn1, OtherColumn2, OtherColumnN

    order by RowNum

    Zeroesque
    805 · 0% · 18
  • Oops, sorry...forgot my aliases.

     

    -- Generate row numbers using a triangle join; must have a primary key and select and group by all columns

    select count(*) as RowNum, a.PrimaryKeyColumn, a.OtherColumn1, a.OtherColumn2, a.OtherColumnN

    from Table1 a

    join Table1 b on a.PrimaryKeyColumn >= b.PrimaryKeyColumn

    group by a.PrimaryKeyColumn, a.OtherColumn1, a.OtherColumn2, a.OtherColumnN

    order by RowNum

    Zeroesque
    805 · 0% · 18

Your Reply


Sign Up or Login to post an answer.

Managed Windows Shared Hosting by OrcsWeb

Copyright © Beyondrelational.com