USE [SGGLDB_XJYJ]
GO

/****** Object:  UserDefinedFunction [dbo].[GetFileName]    Script Date: 2025-3-5 18:28:21 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:        Paul Griffin
-- Create date:   18 January 2015
-- Description:   Returns a filename with extension
--                from a full path:
--                    D:\Temp\Resources\Images\My.Picture.jpg
--                ==> My.Picture.jpg
-- =============================================
ALTER FUNCTION [dbo].[GetFileName]
(
    @Path NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
    DECLARE @FileName NVARCHAR(MAX)
    DECLARE @ReversedPath NVARCHAR(MAX)
	
	SET @Path=REPLACE(@Path,'/','\');
    SET @ReversedPath = REVERSE(@Path)
    
    if CHARINDEX('\', @ReversedPath)>0
    
	SELECT @FileName = RIGHT(@Path, CHARINDEX('\', @ReversedPath)-1)

	RETURN @FileName
  
END
GO


