Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:36:01+00:00 2026-06-12T20:36:01+00:00

Possible Duplicate: ROW_NUMBER() without over in SQL I have a grid with sorting on

  • 0

Possible Duplicate:
ROW_NUMBER() without over in SQL

I have a grid with sorting on each column and have to show only 50 rows at a time.

I am using sql server 2005 as database.

Now there is ROW_NUMBER function in sql server 2005 to filter the data with row number but Over(order by [Column]) is mandatory to use. In my case I have to sort my grid with different columns so I can not use the static columns name in order by clause. The restriction is , I have to use static query.

Can you guys help me out on this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:36:05+00:00Added an answer on June 12, 2026 at 8:36 pm

    Use several ROW_NUMBER clauses per column and choose the relevant one:

    ....
        ROW_NUMBER() OVER (ORDER BY [Column1]) as rn1,
        ROW_NUMBER() OVER (ORDER BY [Column2]) as rn2,
        ROW_NUMBER() OVER (ORDER BY [Column3]) as rn3,
        ROW_NUMBER() OVER (ORDER BY [Column4]) as rn4
    ....
    

    OR use a CASE expression. Note: all datatypes must be compatible

    ROW_NUMBER() OVER (ORDER BY CASE @sort
                         WHEN 1 THEN [Column1]
                         WHEN 1 THEN [Column2]
                         WHEN 1 THEN [Column3]
                         ...
                       END
    

    OR If you really want an arbitrary row number then do this:

    ROW_NUMBER() OVER (ORDER BY (SELECT 1)) as rn
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Concatenate row values T-SQL I have a table like this: ref_num name
Possible Duplicate: SQL Server ROW_NUMBER() on SQL Server 2000? How do I return a
Possible Duplicate: Combine Multiple child rows into one row MYSQL I have following table,
Possible Duplicate: Row Offset in SQL Server I have a query which has a
Possible Duplicate: SQL exclude a column using SELECT * [except columnA] FROM tableA? I
Possible Duplicate: Incrementing a field in SQL using PHP I have a table (T1)
Possible Duplicate: SQL — How is DISTINCT so fast without an index? Hi, I
Possible Duplicate: Find the smallest unused number in SQL Server I have this table
Possible Duplicate: removing specific rows from a dataframe Let's say I have a data
Possible Duplicate: SQL: Find the max record per group I have a table with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.