婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > SQL里面用自定義Split()完成個性化需求

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

熱門標簽:怎么給高德做地圖標注 咸陽電腦外呼系統運營商 慶陽地圖標注 榕城市地圖標注 浙江穩定外呼系統供應商 承德地圖標注公司名需要花錢嗎 電銷外呼系統軟件功能 美團地圖標注商戶認證注冊 北京400電話辦理多少錢
復制代碼 代碼如下:

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

函數、表都建好了,下面調用測試一下吧:
復制代碼 代碼如下:

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)

結果,截個圖來看一下:

標簽:新鄉 江蘇 重慶 呼和浩特 昭通 貴州 拉薩 上海

巨人網絡通訊聲明:本文標題《SQL里面用自定義Split()完成個性化需求》,本文關鍵詞  SQL,里面,用,自定義,Split,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《SQL里面用自定義Split()完成個性化需求》相關的同類信息!
  • 本頁收集關于SQL里面用自定義Split()完成個性化需求的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 襄城县| 札达县| 永新县| 甘德县| 凭祥市| 巴中市| 宁阳县| 晋州市| 永靖县| 慈溪市| 准格尔旗| 宁德市| 泾川县| 曲沃县| 金华市| 江山市| 嘉善县| 拜泉县| 长汀县| 浙江省| 屏南县| 昌吉市| 白水县| 鄂尔多斯市| 兖州市| 八宿县| 礼泉县| 竹山县| 新巴尔虎左旗| 双桥区| 玉林市| 西乌| 沂南县| 高安市| 博兴县| 井陉县| 西丰县| 鹤峰县| 万山特区| 年辖:市辖区| 天水市|