Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use rank() in where clause

Status
Not open for further replies.

BHScripter

Technical User
Aug 26, 2002
159
US
Hi:
I have a SQL script where I use in the select statement:

rank () over (partition by t.person order by lp.dsumest) as rankedbyrent


I would like to break up this query into multiple union statements, so I can add a hardcoded "type" field for each select statement section based on multiple factors. The first item I would like to put into the where clause to create a 'rank1' type is the rank() statement above as:

where rank () over (partition by t.person order by lp.dsumest) = 1

when I do this, I get the following error:

Windowed functions can only appear in the SELECT or ORDER BY clauses.

Is there a way around this?
 
Code:
SELECT * 
FROM (SELECT ......, RANK() OVER ..... AS Test1
            FROM ...) Tbl1 
WHERE Test1 = ???

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top