--get text target starting integers into a table
declare @target TABLE([USERID] varchar(25),[target] int)
--get text stopping point integers into a table
declare @stop TABLE([USERID] varchar(25),[target] int, [stop] int)
--get just the options I want into a table
declare @options TABLE ([USERID] varchar(25), [userDetails] text)
insert into @options ([userid], [userDetails])
select u.userid, rtrim(ltrim(SUBSTRING([userDetails], s.[target], s.[stop] - s.[target])))
from users u join @stop s on u.userid = s.userid
declare @userDetails varchar(max)
Select top 1
@userDetails = [userDetails]
from @options
select charindex(char(32), @userDetails)
All I ever get is 0 from this charindex, i've tried ' ' instead of char(32). I've tried changing the text to varchar but from what I can see that is pointless as text is getting deprecated and is already treated as a varchar?
When i copy and paste the userDetails piece out into a single quoted string and place it into the charindex function things work as expected.
The source text that fills up @userDetails looks like this:
key=value key=value key=value