Thursday, December 25, 2014

How to Change My File Path images Names?

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