Try 'dense_rank() over (order by SaleDocId)'.
SQL SEQUENTIAL NUMBER WITH GROUP , THE OPPOSITE OF PARTITION BY
Hi,
I need to create a Progressive Number on different group in a Select on SQL, the number should be progressive with different group , but the same inside the same group.
Here is the code i use now with the result :
select
ROW_NUMBER()OVER(PARTITION BY SD.SALEDOCID ORDER BY sd.DOCNO ASC) AS ProgressivoDocumento,
sd.SaleDocId ,
cs.custsupp ,
'CINV' AS TipoDocument,
sd.DocNo As NumeroDocumento,
sd.DocumentDate as DataEmissioneDocumento
from MA_SaleDoc SD
JOIN MA_PyblsRcvbls PY on sd.DocNo = py.DocNo
right join MA_CustSupp CS on cs.CustSupp = sd.CustSupp
join MA_SaleDocSummary sds on sd.SaleDocId = sds.SaleDocId
join MA_SaleDocPymtSched sdp on sdp.SaleDocId = sd.SaleDocId
where
( sd.DocumentType = '3407874'or sd.DocumentType = '3407875') and py.Settled = 0 and sd.DocumentDate >='20210101' and py.DocumentDate >='20210101' AND CS.CustSuppType = '3211264'
And this is what i find
But i need exactly the opposite like this :
Can someone help me on how to solve this?
Thank you very much
Developer technologies Transact-SQL
SQL Server Other
1 additional answer
Sort by: Most helpful
-
EchoLiu-MSFT 14,621 Reputation points
2021-10-28T06:34:15.237+00:00 Hi @daniele franzini ,
Welcome to the microsoft TSQL Q&A forum!
The DENSE_RANK() function mentioned by Viorel-1 can solve your problem. Please refer to his answer. For more details, please refer to:
DENSE_RANK (Transact-SQL)Regards
Echo