/*
实现split功能的函数,拆分为NVARCHAR类型
*/
CREATE FUNCTION [dbo].[FUN_SplitCharsNvarchar](@SourceSql NVARCHAR(4000),@StrSeprate NVARCHAR(10))
RETURNS NVARCHAR(4000)
AS
BEGIN
DECLARE @temp NVARCHAR(4000)
SET @temp = ''
DECLARE @i INT
SET @SourceSql=RTRIM(LTRIM(UPPER(@SourceSql)))
SET @i=CHARINDEX(@StrSeprate,@SourceSql)
WHILE @i>=1
BEGIN
SET @temp = @temp + '''' + RTRIM(LTRIM(LEFT(@SourceSql,@i-1))) + ''','
SET @SourceSql=SUBSTRING(@SourceSql,@i+1,LEN(@SourceSql)-@i)
SET @i=CHARINDEX(@StrSeprate,@SourceSql)
END
IF @temp <> ''
BEGIN
SET @temp = @temp + '''' + @SourceSql + ''''
END
ELSE
BEGIN
SET @temp= '''' + @SourceSql + ''''
END
RETURN @temp
END
调用:
select [dbo].[FUN_SplitCharsNvarchar]('123456789','56')