Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
HiThis is my query.. If am run this query i will get error for Invalid column RowID bcoz i generate the rowid in select clause.what should i do to solve this without using CTE & Temp table...please help on this..SELECT RANK() OVER (ORDER BY COST DESC) AS ROWID, COL1, COL2, COL3, COL4, COL5FROM TABLE_NAMEWHERE ROWID BETWEEN 1 AND 20ORDER BY COL1 DESC-------------------------R..
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2009-07-24 : 01:46:48
There is no difference between a CTE or a derived table.But some tools are not updated to handle CTE.
SELECT Col1, Col2, Col3, Col4, Col5FROM ( SELECT RANK() OVER (ORDER BY Cost DESC) AS RowID, Col1, Col2, Col3, Col4, Col5 FROM Table_Name ) AS dWHERE RowID BETWEEN 1 AND 20ORDER BY Col1 DESC