I have the below query.
I can only have possible 7 characters (- and A-Z combined)
There can only be ONE "-" for first 5 characters (Monday to Friday) For Saturday and Sunday, we can only have one character or dash I am replacing Sa and Su with just S
However, whenever they are passing in TWO dashes for Saturday AND/OR Sunday, I need to replace them with ONE dash for each
so length can only be 7 after all manipulations.
I have tried w/e I could but getting stuck at the two vs one dash scenario for Saturday/Sunday position.
Please help! I will keep this updated as I find more.
THX in ADV
Code:
CREATE Table TempTable (string varchar(50))
INSERT INTO TempTable (string)
VALUES ('MTWRFSS')
,('MTWRFSaS')
,('MTWRFSaSu')
,('----F--')
,('----F----')
,('MT------')
,('MT------')
,('----FSa--')
,('----FSa-')
,('----FS--')
,('----FS-')
,('----F-Su')
,('----F--Su')
,('----F-S')
,('----F--S')
UPDATE TempTable
SET string = REPLACE(REPLACE(RTRIM(LTRIM(string)),'SA','S'),'SU','S')
SELECT string
,LEN(String) AS stringLengh FROM TempTable
--DROP TABLE TempTable