I want implement this pseudocode in t-sql
UPDATE Resources SET [Path]= CASE ([Path].Substring([Path].LastIndexOf('.')))
WHEN '.jpg' THEN '/image.jpg'
WHEN '.png' THEN '/image.jpg'
WHEN '.avi' THEN '/video.jpg'
WHEN '.mkv' THEN '/video.jpg'
for it I use this solution
UPDATE Resources SET [Path] = CASE (SUBSTRING([Path], LEN([Path]) - CHARINDEX('.', REVERSE([Path])) + 1, 3))
WHEN '.jpg' THEN '/image.jpg'
WHEN '.png' THEN '/image.jpg'
WHEN '.avi' THEN '/video.jpg'
WHEN '.mkv' THEN '/video.jpg'
END
but it is does not return expected result.
Can anyone give me working version please?
Your read of the extension is wrong, instead try:
(Using
LEN(Path)as the read length; fine if it overflows the end of the string and allows for n-character extensions)