Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Conocer si los datos de un registro son correlativos

Buen dia a tod@s

Estoy generando una consulta en MSSQL SERVER 2008

Esta me tiene que arrojar el primer y ultimo numero de un rango de facturas de un mes, pero, si estos son correlativos, de no ser asi los numero que dentro de ese rango de datos no sean correlativos me los imprima aparte.

SELECT T1.[SlpName] 'VENDEDOR',
        (SELECT MIN(T0.[NumAtCard]) 
         FROM OINV T0
					 LEFT JOIN OSLP T1 ON T0.[SlpCode] = T1.[SlpCode] 
			   WHERE T0.DocDate = '[%1]' AND T0.[NumAtCard] LIKE '%F%' AND T1.[SlpName] = '[%0]'), 
        (SELECT MIN(T0.[NumAtCard]) 
         FROM OINV T0
					 LEFT JOIN OSLP T1 ON T0.[SlpCode] = T1.[SlpCode] 
			   WHERE T0.DocDate = '[%1]' AND T0.[NumAtCard] LIKE '%C%' AND T1.[SlpName] = '[%0]')      
FROM OINV T0
	LEFT JOIN OSLP T1 ON T0.[SlpCode] = T1.[SlpCode]
WHERE T0.[DocDate] = '[%1]' AND
         T0.[NumAtCard] NOT LIKE '%REDIGIT%' AND
         T0.[NumAtCard] NOT LIKE '%ANUL%' AND
         T1.[SlpName] = '[%0]'
GROUP BY T0.[DocDate], T1.[SlpName]

UNION

SELECT T1.[SlpName] 'VENDEDOR',
        (SELECT MAX(T0.[NumAtCard]) 
         FROM OINV T0 
					 LEFT JOIN OSLP T1 ON T0.[SlpCode] = T1.[SlpCode] 
			   WHERE T0.DocDate = '[%2]' AND T0.[NumAtCard] LIKE '%F%' AND T1.[SlpName] = '[%0]'), 
        (SELECT MAX(T0.[NumAtCard]) 
         FROM OINV T0 
					 LEFT JOIN OSLP T1 ON T0.[SlpCode] = T1.[SlpCode] 
			   WHERE T0.DocDate = '[%2]' AND T0.[NumAtCard] LIKE '%C%' AND T1.[SlpName] = '[%0]')        
FROM OINV T0
	LEFT JOIN OSLP T1 ON T0.[SlpCode] = T1.[SlpCode]
WHERE T0.[DocDate] = '[%2]' AND
         T0.[NumAtCard] NOT LIKE '%REDIGIT%' AND
         T0.[NumAtCard] NOT LIKE '%ANUL%' AND
         T1.[SlpName] = '[%0]'
GROUP BY T0.[DocDate], T1.[SlpName]

Se que para esto debe haber una funcion y por eso acudoa ustedes cual es la mas conveniente?

Former Member
Not what you were looking for? View more on this topic or Ask a question