The following SQL retrieved the latest wave name based on the number suffix.
This is a wave name structure:XXX_XXX_XXXXXXXXXX.XXXX_< incremented number >
Example: XXX_XXX_XXXXXXXXXX.XXXX_1 , XXX_XXX_XXXXXXXXXX.XXXX_2, XXX_XXX_XXXXXXXXXX.XXXX_3
select top 1 wave
from Outbound co WHERE Program = :Program
order by CAST(SUBSTRING(SUBSTRING(Wave, CHARINDEX('.', Wave)+ 1, len(wave)), PATINDEX('%[_]%',
SUBSTRING(Wave, CHARINDEX('.', Wave)+ 1, len(wave)))+ 1, LEN(SUBSTRING(Wave, CHARINDEX('.', Wave)+ 1, len(wave)))) AS INT) desc;
Lately, I notice that the wave name structure changed, there for the current SQL logic will not be applicable with the new format.
New format: XXXX_XXXXXX_XXX.XXXXXXXXX_XXXX_XXXX__< incremented number > _< monthyear >
Example: XXXX_XXXXXX_XXX.XXXXXXXXX_XXXX_XXXX_81_042122, XXXX_XXXXXX_XXX.XXXXXXXXX_XXXX_XXXX_80_032122
I would like to extend the current SQL logic to handle both scenarios in one SQL.
Any advice on how?
Thanks