From: Iain Sharp on

Check that your database is not set to compatability 80 (SQL 2000)

Iain

On Fri, 21 May 2010 07:39:01 -0700, Qaspec
<Qaspec(a)discussions.microsoft.com> wrote:

>I'm getting the following error -
>
>'ROW_NUMBER' is not a recognized function name.
>
>I am working with Microsoft SQL Server 2005 - Management Studio
>
>"Plamen Ratchev" wrote:
>
>> I am not sure I understand, but try the following query:
>>
>> SELECT CNumber, CreateDate
>> FROM (
>> SELECT CNumber, CreateDate, ROW_NUMBER() OVER(ORDER BY CreateDate) AS
>> rk
>> FROM dbo.tblOrder
>> WHERE CreateDate BETWEEN '20100101' AND '20100501'
>> AND CNumber = '0514') AS T
>> WHERE rk = 2;
>>
>> --
>> Plamen Ratchev
>> http://www.SQLStudio.com
>> .
>>
From: Uri Dimant on
CREATE TABLE #tmp (c INT)

INSERT INTO #tmp VALUES (100)

INSERT INTO #tmp VALUES (200)

INSERT INTO #tmp VALUES (300)


SELECT TOP 1* FROM

(SELECT TOP 2 * FROM #tmp ORDER BY c )

AS D ORDER BY c DESC





"Qaspec" <Qaspec(a)discussions.microsoft.com> wrote in message
news:B7D762D9-714B-476C-A170-1E4046041DE6(a)microsoft.com...
>I want to find the next greater value after min for "NextOrder". I'm
> currently using Max but I know there are orders that have a date greater
> than
> the Min but less that the Max....can this be done?
>
> SELECT CNumber, Min (CreateDate) as FirstOrder, Max (CreateDate) as
> NextOrder
> FROM dbo.tblOrder (nolock)
>
> Where CreateDate Between '1/1/10' and '5/1/10' and CNumber = '0514'
>
> Group By CustomerNumber