我有string
格式'S1CW3733|1050105000224,S1CW4923|1050105000009'
我在 SQL 中有将其转换为格式的函数
item
S1CW3733|1050105000224
S1CW4923|1050105000009
可以这样做吗?(多列)
item item2
S1CW3733 1050105000224
S1CW4923 1050105000009
我的功能:-
ALTER Function [dbo].[fnSplit]
(
@sInputList Varchar(8000), -- List of delimited items
@sDelimiter VarChar(8000) = ',' -- delimiter that separates items
)
Returns @List Table (item VarChar(8000))
Begin
Declare @sItem VarChar(8000)
While CharIndex(@sDelimiter,@sInputList,0) <> 0
Begin
Select
@sItem=RTrim(LTrim(SubString(@sInputList,1,CharIndex(@sDelimiter,@sInputList,0)-1))),
@sInputList=RTrim(LTrim(SubString(@sInputList,CharIndex(@sDelimiter,@sInputList,0)+Len(@sDelimiter),Len(@sInputList))))
If Len(@sItem) > 0
Insert Into @List Select @sItem
End
If Len(@sInputList) > 0
Insert Into @List Select @sInputList -- Put the last item in
Return
End