I have a string in the database which is comma separated.Like \'apple,banana,pineapple,grapes\' I need to split this string on the basis of comma and iterate through this.Si
... Since there is no built in function in sql server ...
That was true at the time you asked this question but SQL Server 2016 introduces STRING_SPLIT.
So you can just use
SELECT value
FROM STRING_SPLIT ('apple,banana,pineapple,grapes', ',')
There are some limitations (only single character delimiters accepted and a lack of any column indicating the split index being the most eye catching). The various restrictions and some promising results of performance testing are in this blog post by Aaron Bertrand.