I forgot to mention I'm on SQL 2000. I copied and pasted but the
expression gets errors on that and on row_number:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ';'.
Server: Msg 195, Level 15, State 1, Line 7
'row_number' is not a recognized function name.
> It's how you do a Common Table Expression (CTE) in SQL Server 2005. Just
> cut and paste.
[quoted text clipped - 79 lines]
>
> - Show quoted text -
It's important that you do mention which version of SQL Server you are
using. SQL 2005 is current and we usually assume that you are using it,
unless you specify otherwise. Here's an example from Northwind that takes
the 3 most-recent orders for each customer:
select
*
from
Orders o1
where
3 >
(
select
count (*)
from
Orders o2
where
o2.CustomerID = o1.CustomerID
and (o2.OrderDate > o1.OrderDate
or (o2.OrderDate = o1.OrderDate
and o2.OrderID > o1.OrderID))
)
order by
o1.CustomerID
, o1.OrderDate desc

Signature
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
I forgot to mention I'm on SQL 2000. I copied and pasted but the
expression gets errors on that and on row_number:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ';'.
Server: Msg 195, Level 15, State 1, Line 7
'row_number' is not a recognized function name.
On Jul 2, 2:43 pm, "Tom Moreau" <t...@dont.spam.me.cips.ca> wrote:
> It's how you do a Common Table Expression (CTE) in SQL Server 2005. Just
> cut and paste.
[quoted text clipped - 80 lines]
>
> - Show quoted text -
mar - 03 Jul 2008 17:38 GMT
My bad on the SQL version.
THANK YOU! I got it working on my tables!
mar.
> It's important that you do mention which version of SQL Server you are
> using. SQL 2005 is current and we usually assume that you are using it,
[quoted text clipped - 126 lines]
>
> - Show quoted text -