I am using this logic to split the string query
declare @query nvarchar(max)
set @query = '1&2&3&4&5&6&7&8&9&10&11&12&13&14'
SELECT SUBSTRING('&' + @query + '&', Number + 1, -- is used to split the '@query' on the basis of '&' sign
CHARINDEX('&', '&' + @query + '&', Number + 1) - Number -1)AS VALUE
FROM master..spt_values
WHERE Type = 'P'
AND Number <= LEN('&' + @query + '&') - 1
AND SUBSTRING('&' + @query + '&', Number, 1) = '&'
It works fine when query is small, but its giving me less result then actual when the value of @query is very large
For eg.
@query = 'very large string containing 60 & sign '
returns only 10 records
How can I split large string, and what is the reason? Why can SUBSTRING
not handle large strings?