Link to home
Start Free TrialLog in
Avatar of Bharat Guru
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
Avatar of Philippe Damerval
Philippe Damerval
Flag of United States of America image

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)

Thx

Philippe
ASKER CERTIFIED SOLUTION
Avatar of devlab2012
devlab2012
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bharat Guru
Bharat Guru

ASKER

I just updated following statement and it worked perfectly
set @cp = 0

Thannks