Update Survey_QuestionColumns set ColumnPath = '1 | 3 | 1000 | 6 'where ColumnPath = '1 | 3 | 4 | 6'
Create function Spliaaaa
(
@ List nvarchar (2000), -- string to be separated
@ SplitOn nvarchar (5), -- delimiter
@ Num int
)
RETURNS varchar (50)
As
BEGIN
Declare @ aaa varchar (50)
Declare @ RtnValue table
(
Id int identity (1, 1 ),
[Value] nvarchar (100)
)
While (Charindex (@ SplitOn, @ List)> 0)
Begin
Insert Into @ RtnValue ([Value])
Select
[Value] = ltrim (rtrim (Substring (@ List, 1, Charindex (@ SplitOn, @ List)-1 )))
Set @ List = Substring (@ List, Charindex (@ SplitOn, @ List) + len (@ SplitOn), len (@ List ))
End
Insert Into @ RtnValue ([Value])
Select [Value] = ltrim (rtrim (@ List ))
Select @ aaa = [Value] from @ RtnValue where Id = @ num-1
Return @ aaa
END
Go
Select * from Survey_QuestionColumns where dbo. Spliaaaa (ColumnPath, '|', 3) = '3'
Drop function Spliaaaa