podria quedar con esto tomando en cuenta los datos que muestras :P
Código SQL:
Ver originalCREATE TABLE #temp
(
Nro INT,
ItemCode VARCHAR(20),
ItmsGrpCod INT,
DocDate datetime
)
INSERT INTO #temp VALUES (1,'L1-001 EXTRA',115,'2014-03-12 00:00:00.000')
INSERT INTO #temp VALUES (2,'L1-001 EXTRA',115,'2014-03-11 00:00:00.000')
INSERT INTO #temp VALUES (3,'L1-001 EXTRA',115,'2014-03-07 00:00:00.000')
INSERT INTO #temp VALUES (4,'L1-001 EXTRA',115,'2014-03-07 00:00:00.000')
INSERT INTO #temp VALUES (5,'L1-001 EXTRA',115,'2014-03-07 00:00:00.000')
INSERT INTO #temp VALUES (6,'L1-001 EXTRA',115,'2014-03-06 00:00:00.000')
INSERT INTO #temp VALUES (7,'L1-001 EXTRA',115,'2014-02-21 00:00:00.000')
INSERT INTO #temp VALUES (8,'L1-001 EXTRA',115,'2014-02-19 00:00:00.000')
INSERT INTO #temp VALUES (9,'L1-001 EXTRA',115,'2014-02-11 00:00:00.000')
INSERT INTO #temp VALUES (10,'L1-001 EXTRA',115,'2014-02-05 00:00:00.000')
INSERT INTO #temp VALUES (11,'L1-001 EXTRA',115,'2014-02-03 00:00:00.000')
INSERT INTO #temp VALUES (12,'L1-001 EXTRA',115,'2014-02-01 00:00:00.000')
INSERT INTO #temp VALUES (13,'L1-001 EXTRA',115,'2014-01-28 00:00:00.000')
INSERT INTO #temp VALUES (14,'L1-001 EXTRA',115,'2014-01-23 00:00:00.000')
INSERT INTO #temp VALUES (15,'L1-001 EXTRA',115,'2014-01-21 00:00:00.000')
INSERT INTO #temp VALUES (16,'L1-001 EXTRA',115,'2014-01-18 00:00:00.000')
INSERT INTO #temp VALUES (17,'L1-001 EXTRA',115,'2014-01-02 00:00:00.000')
INSERT INTO #temp VALUES (18,'L1-001 EXTRA',115,'2013-12-30 00:00:00.000')
INSERT INTO #temp VALUES (19,'L1-001 EXTRA',115,'2013-12-28 00:00:00.000')
INSERT INTO #temp VALUES (20,'L1-001 EXTRA',115,'2013-12-18 00:00:00.000')
INSERT INTO #temp VALUES (1,'L1-001 NOVEX',115,'2014-03-15 00:00:00.000')
INSERT INTO #temp VALUES (2,'L1-001 NOVEX',115,'2014-03-13 00:00:00.000')
INSERT INTO #temp VALUES (3,'L1-001 NOVEX',115,'2014-03-07 00:00:00.000')
INSERT INTO #temp VALUES (4,'L1-001 NOVEX',115,'2014-03-07 00:00:00.000')
INSERT INTO #temp VALUES (5,'L1-001 NOVEX',115,'2014-03-06 00:00:00.000')
INSERT INTO #temp VALUES (6,'L1-001 NOVEX',115,'2014-03-04 00:00:00.000')
INSERT INTO #temp VALUES (7,'L1-001 NOVEX',115,'2014-02-27 00:00:00.000')
INSERT INTO #temp VALUES (8,'L1-001 NOVEX',115,'2014-02-25 00:00:00.000')
INSERT INTO #temp VALUES (9,'L1-001 NOVEX',115,'2014-02-22 00:00:00.000')
INSERT INTO #temp VALUES (10,'L1-001 NOVEX',115,'2014-02-22 00:00:00.000')
INSERT INTO #temp VALUES (11,'L1-001 NOVEX',115,'2014-02-19 00:00:00.000')
SELECT * FROM #temp WHERE Nro BETWEEN 1 AND 5
creo que la falla fue el where final en lugar de
WHERE nro <=5
pruebalo con:
Código SQL:
Ver originalSELECT *
FROM
(
SELECT
ROW_NUMBER() OVER(PARTITION BY V.ItemCode ORDER BY V.DocDate DESC) AS [Nro], V.ItemCode, B.ItmsGrpCod, V.DocDate
FROM INV1 V
INNER JOIN OITM M ON V.ItemCode=M.ItemCode
INNER JOIN OITB B ON M.ItmsGrpCod=B.ItmsGrpCod) t1
WHERE nro BETWEEN 1 AND 5
saludos!