How to write a function which returns substring between commas.
example :
@TempString = "25,134,315,124,248,15,"
select myfunction(@TempString, 3, ',')
should return : 315
select myfunction(@TempString, 4, ',')
should return : 124
Microsoft SQL ServerSQL
Last Comment
Bharat Guru
8/22/2022 - Mon
Philippe Damerval
Hi,
This pseudocode should help you
function getStringAtCommaNumber (StringParm, commaPosition)
Define Stringvar as string variable
Define dynamic array of strings
while (position of comma in string > 0)
add (left part of string up to first comma position) to array
Reassign whatever is right of the same position to stringvar
end while
if stringvar not empty then add stringvar to array
return element of array at position commaposition - 1
end
The question is just 100 points after all :) I hope this helps. You will find all the reference information you need by looking up SQL server string functions (position, left, right, etc)
This pseudocode should help you
function getStringAtCommaNumber (StringParm, commaPosition)
Define Stringvar as string variable
Define dynamic array of strings
while (position of comma in string > 0)
add (left part of string up to first comma position) to array
Reassign whatever is right of the same position to stringvar
end while
if stringvar not empty then add stringvar to array
return element of array at position commaposition - 1
end
The question is just 100 points after all :) I hope this helps. You will find all the reference information you need by looking up SQL server string functions (position, left, right, etc)
Thx
Philippe