Solved

Ms sql problem with row_number query

Posted on 2010-09-02
2
221 Views
Last Modified: 2012-05-10
I have this query:

SELECT req_n,ROW_NUMBER() OVER (ORDER BY req_n) AS ROWID from req

Works fine...

How ever if I try ti limit to a specific row:

SELECT req_n,ROW_NUMBER() OVER (ORDER BY req_n) AS ROWID from req where rowid=5

I get a messahe rowid is an invalida column.

How can I do this?
0
Comment
Question by:robrodp
2 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 500 total points
ID: 33589423
Quick and dirty - cheat:

SELECT req_n, RowID
FROM (
    SELECT req_n,ROW_NUMBER() OVER (ORDER BY req_n) AS ROWID from req
    ) Src
WHERE RowID = 5
0
 
LVL 16

Expert Comment

by:vdr1620
ID: 33589849
you can also try this below SQL

SELECT req_n,ROW_NUMBER() OVER (ORDER BY req_n) AS ROWID from req
where
ROW_NUMBER() OVER (ORDER BY req_n) =5
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Query 18 80
TSQL Update Field Older Than 5 Days 10 44
mySql Syntax 7 27
mySQL. SQL query. Substitute for Numeric key word. 3 33
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

21 Experts available now in Live!

Get 1:1 Help Now