Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
extract part of a string
--extract part of a string create function dbo.GetStringParts ( @str nvarchar(max), @separator char(1) ) returns table AS return ( with tokens(p, a, b) AS ( select cast(1 as bigint), cast(1 as bigint), charindex(@separator, @str) union all select p + 1, b + 1, charindex(@separator, @str, b + 1) from tokens where b > 0 ) select p-1 AS ItemIndex, substring(@str, a, case when b > 0 then b-a else LEN(@str) end) AS Item from tokens ); go --usage select * from dbo.GetStringParts('Hello,John,Smith', ',') where ItemIndex >= 0 and ItemIndex < 4 --OPTION ( MAXRECURSION 0) --if more than 100 elements; 0 - disables recursion limit, non-0 is the number of allowd recursions
run
|
edit
|
history
|
help
0
try catch, raiserror and throw
SQL CASE WHEN
SQL Server : Calculate Going Step (Yutthana Thanomklay)
Deepak
bc160401693
Campeonato2DLuizFelipe
SQL Server - NULL values with IN and NOT IN (Solution)
Program 3 Lab Assignment
Alquileres
BC160400549