ImageFile
FullFileName
INT
LastSlashPos
LastDotPos
update dbo.ImageFile set LastSlashPos = len(FullFileName) - charindex('\', reverse(FullFileName)) + 1 ,LastDotPos = len(FullFileName) - charindex('.', reverse(FullFileName)) + 1 ----------------------------- update dbo.ImageFile set FileExtension = substring(FullFileName, LastDotPos+1,Len(FullFileName)) FileNameWithoutExt = substring(FullFileName, LastSlashPos+1, LastDotPos-LastSlashPos-1)
/* select result = dbo.udsFileExtension('hello.vbs.txt.xml') */ ALTER function [dbo].[udsFileExtension] ( @file varchar(max) ) returns varchar(max) as begin declare @result varchar(max) ,@pos int select @pos = len(@file) - charindex('.', reverse(@file)) + 1 ,@result = case when @file like '%.%' then substring(@file, @pos, len(@file)) else '' end return @result end