Try this script:
DECLARE @imagePath varchar(128)
DECLARE @fileName varchar(64)
SET @imagePath = '~\Upload\1_cat.GIF'
SET @fileName = 'NewName'
SELECT
@imagePath AS [ImagePathFromDB]
, (
REVERSE(
SUBSTRING(
REVERSE(@imagePath), CHARINDEX('\', REVERSE(@imagePath), 0), LEN(REVERSE(@imagePath)) - CHARINDEX('\', REVERSE(@imagePath), 0) + 1
)
) -- Sub string before file name, i.e., "~\Upload\"
+
@filename -- New file name, i.e., "NewName"
+
REVERSE(
LEFT(
REVERSE(@imagePath), CHARINDEX('.', REVERSE(@imagePath), 0)
) -- . + file extension, i.e., ".gif"
)
) AS [ImagePathYouWant]
A Fan of SSIS, SSRS and SSAS
No comments:
Post a Comment