最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SQL里面用自定義Split()完成個性化需求

 更新時間:2013年02月21日 15:06:14   作者:  
為了滿足需求自定義Split()在SQL中實(shí)現(xiàn),代碼很整潔,感興趣的朋友可以參考下,或許對你學(xué)習(xí)sql語句有所幫助
復(fù)制代碼 代碼如下:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[SplitString]
(
@Input nvarchar(max),
@Separator nvarchar(max)=',',
@RemoveEmptyEntries bit=1
)
returns @TABLE table
(
[Id] int identity(1,1),
[Value] nvarchar(max)
)
as
begin
declare @Index int, @Entry nvarchar(max)
set @Index = charindex(@Separator,@Input)
while (@Index>0)
begin
set @Entry=ltrim(rtrim(substring(@Input, 1, @Index-1)))
if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'')
begin
insert into @TABLE([Value]) Values(@Entry)
end
set @Input = substring(@Input, @Index+datalength(@Separator)/2, len(@Input))
set @Index = charindex(@Separator, @Input)
end
set @Entry=ltrim(rtrim(@Input))
if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'')
begin
insert into @TABLE([Value]) Values(@Entry)
end
return
end

函數(shù)、表都建好了,下面調(diào)用測試一下吧:
復(fù)制代碼 代碼如下:

declare @str1 varchar(max), @str2 varchar(max), @str3 varchar(max)
set @str1 = '1,2,3'
set @str2 = '1###2###3'
set @str3 = '1###2###3###'
select [Value] from [dbo].[SplitString](@str1, ',', 1)
select [Value] from [dbo].[SplitString](@str2, '###', 1)
select [Value] from [dbo].[SplitString](@str3, '###', 0)

結(jié)果,截個圖來看一下:

相關(guān)文章

最新評論

韶山市| 南漳县| 全南县| 嫩江县| 禄丰县| 莆田市| 商水县| 芒康县| 政和县| 酉阳| 习水县| 迁西县| 巴彦淖尔市| 孝义市| 松溪县| 丰都县| 安化县| 永善县| 雷山县| 庆城县| 长海县| 随州市| 开封市| 门头沟区| 淮南市| 天水市| 永靖县| 龙州县| 洪洞县| 阿克苏市| 丰镇市| 苏尼特左旗| 丰顺县| 池州市| 电白县| 日喀则市| 达孜县| 平阴县| 新密市| 咸阳市| 塔河县|