SELECT ISNULL
(
MAX(RSERV_NB) + 1 , RIGHT(CAST(DATEPART(YY, GETDATE()) AS VARCHAR(4)), 2) + RIGHT(REPLICATE('0', 2) + CAST(DATEPART(dy, getDate()) AS VARCHAR(3)) , 3) + '0001'
)
FROM DD
WHERE RSERV_NB > RIGHT(CAST(DATEPART(YY, GETDATE()) AS VARCHAR(4)), 2) + RIGHT(REPLICATE('0', 2) + CAST(DATEPART(dy, getDate()) AS VARCHAR(3)) , 3) + '0000'
|