I have a table dates
with a column SENTDATE
where each row has a varying number of dates in it, separated by a semi colon (;
). The dates are currently in the format YYYYMMDD - for example:
20240529;20240626;20240626;20240626;20240626;20240626
20240530;20240620
20240605
20240523;20240523
I'm attempting to convert each of these dates into the format DD/MM/YYYY and keep them delimited by the semicolon so they look like this:
29/05/2024;26/06/2024;26/06/2024;26/06/2024;26/06/2024
30/05/2024;20/06/2024
Unfortunately, I am using SQL Server 2005, so in order to change the formats I need to use SUBSTRING
and then combine the different portions of the dates, interspersed with forward slashes:
SUBSTRING(SENTDATE, 1, 4) + '/' + SUBSTRING(SENTDATE, 5, 2) + '/' + SUBSTRING(SENTDATE, 7, 2)
but that's no issue.
Would you know of a way of being able to process each date between the semi colons? I'm assuming it'll be some sort of split and then recombination of the string?
I haven't actually tried anything here. I could use PARSENAME
but I have no clue how to do that with varying numbers of delimiters.
Thank you.
STRING_SPLIT()
andSTRING_AGG()
.