Bharat Guru
asked on
how to find substring between 3rd and 4th comma
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
example :
@TempString = "25,134,315,124,248,15,"
select myfunction(@TempString, 3, ',')
should return : 315
select myfunction(@TempString, 4, ',')
should return : 124
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I just updated following statement and it worked perfectly
set @cp = 0
Thannks
set @cp = 0
Thannks
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