/files/ajaxren/分隔字串.rar
alter
procedure
sp_split_string
(@string
nvarchar
(4000
),--
要分割的字串
@splitstring
varchar
(2000
) --
中間的分割符)as
begin
declare
@object_id
nvarchar
(500
)declare
@iint
declare
@len
intprint
@string
if(@string
isnull
) or
(ltrim
(@string) =
'')return
--查詢字串@string的中是否包含@splitstring字元
while
charindex
(@splitstring
,@string
) >
0begin
set@len
=len
(@string)--
總的長度
@len
set@i
=charindex
(@splitstring
, @string)--
找到第乙個包含分割符的地方
@iset@object_id
=left
(@string
, @i-1
)--擷取開始到分割前乙個資料(分割資料)--右邊開始算
'object_id='+
@object_id
---insert into a (id) values (@object_id)--少做修改,改成需要的sql語句即可
set@string
=right
(@string
, @len-@i
)--給變數從新複製資料-從分割符後面到整個長度-right從左邊開始算
endset@object_id
=@string
--insert into a (id) values (@object_id)--少做修改,改成需要的sql語句即可
endgo
exec
sp_split_string
'102,103,105,106,107,108,200,500,306,408',','
SQL 字串分割函式
create function dbo f split sourcesql varchar 8000 strseprate varchar 10 returns temp table a varchar 100 as begin declare iint set sourcesql rtrim lt...
SQL 字串分割函式
create function dbo split input varchar max split varchar max returns table table col varchar max as begin while charindex split,input 0 begin insert ...
分割字串的sql函式
create function stringtotable stringx varchar 8000 split nvarchar 10 returns tableresult table tableid nvarchar 100 as begin declare index int declare...