sql server 取文件名函数 转载
/****** Object: UserDefinedFunction [dbo].[GetDirectoryPath] Script Date: 2016-12-16 16:54:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[GetDirectoryPath]
(
@Path NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @FileName NVARCHAR(MAX)
DECLARE @ReversedPath NVARCHAR(MAX)
DECLARE @PathLength INT
SET @ReversedPath = REVERSE(@Path)
SELECT @PathLength = CHARINDEX('/', @ReversedPath)
SELECT @FileName = LEFT(@Path, LEN(@Path) - @PathLength)
RETURN @FileName
END
GO
/****** Object: UserDefinedFunction [dbo].[GetExtension] Script Date: 2016-12-16 16:54:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[GetExtension]
(
@Path NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @FileName NVARCHAR(MAX)
DECLARE @ReversedPath NVARCHAR(MAX)
DECLARE @ExtLength INT
SET @ReversedPath = REVERSE(@Path)
SET @FileName = ''
SELECT @ExtLength = CHARINDEX('.', @ReversedPath)
IF (@ExtLength > 0)
BEGIN
SELECT @FileName = RIGHT(@Path, @ExtLength - 1)
END
RETURN @FileName
END
GO
/****** Object: UserDefinedFunction [dbo].[GetFileName] Script Date: 2016-12-16 16:54:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[GetFileName]
(
@Path NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @FileName NVARCHAR(MAX)
DECLARE @ReversedPath NVARCHAR(MAX)
SET @ReversedPath = REVERSE(@Path)
SELECT @FileName = RIGHT(@Path, CHARINDEX('/', @ReversedPath)-1)
RETURN @FileName
END
GO
/****** Object: UserDefinedFunction [dbo].[GetFileNameWithoutExtension] Script Date: 2016-12-16 17:32:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[GetFileNameWithoutExtension]
(
@Path NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @FileName NVARCHAR(MAX)
DECLARE @ReversedPath NVARCHAR(MAX)
DECLARE @ExtLength INT
SET @ReversedPath = REVERSE(@Path)
SELECT @ExtLength = CHARINDEX('.', @ReversedPath)
SELECT @FileName = (case when CHARINDEX('/', @ReversedPath)>0 then RIGHT(@Path, CHARINDEX('/', @ReversedPath)-1) else @Path end)
SELECT @FileName = LEFT(@FileName, LEN(@FileName) - @ExtLength)
RETURN @FileName
END
GO
/****** Object: UserDefinedFunction [dbo].[RepEmpty] Script Date: 2016-12-16 16:54:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[RepEmpty] (@sourcedata varchar(8000))
RETURNS VARCHAR(8000)
AS
BEGIN
return isnull(rtrim(ltrim(replace(replace(replace(replace(@sourcedata,char(9),''),char(10),''),char(13),''),'',''))),'')
END
GO
/****** Object: UserDefinedFunction [dbo].[Split] Script Date: 2016-12-16 16:54:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[Split](@Long_str varchar(8000),@split_str varchar(100))
returns @t table(id int,item varchar(20))
as
begin
declare @id int
set @id=1
while(charindex(@split_str,@Long_str) <> 0)
begin
insert @t(id,item) values(@id,substring(@Long_str,1,charindex(@split_str,@Long_str)-1))
set @Long_str = stuff(@Long_str,1,charindex(@split_str,@Long_str), ' ')
set @id=@id+1
end
insert @t(id,item) values (@id,@Long_str)
return
end
GO
最新文章
- MySQL多表查询
- 【原创】Android内存管理-OnTrimMemory
- 【Python数据分析】简单爬虫 爬取知乎神回复
- Activity按下2次退出和获取当前时间
- setTimeout方法
- Android之Service
- Ossec常用命令
- POJ 3660 Cow Contest (Floyd)
- SQL 查询同一天日期内的数据
- java poi 从服务器下载模板写入数据再导出
- 从零开始学 Web 之 移动Web(三)Zepto
- android listview优化:滑动时颜色错乱问题
- [技术] OIer的C++标准库 : STL入门
- 最大容积 Container With Most Water
- Engineering Management
- zookeeper的配置参数详解(zoo.cfg)
- New Concept English Two 32 88
- C++ 静多态与动多态
- python&#39;s fourteenth day for me 内置函数
- Oracle通过PLSQL进行数据表之间的同步
热门文章
- Elasticsearch之java的基本操作一
- nodejs进阶(4)—读取图片到页面
- 我为什么要写LeetCode的博客?
- KV存储系统
- Python标准模块--Unicode
- webpack学习总结
- AFNetworking报错";_UTTypeCopyPreferredTagWithClass";, referenced from: _AFContentTypeForPathExtens
- git提交项目到已存在的远程分支
- wireshark 相关提示
- POJ1743 Musical Theme [后缀数组]