Originally Posted by sonic8
Focus on this part:
SET @strInprocess = rtrim(LEFT(@strinput,CHARINDEX(' ',@strinput)))
Are you aware that this will set @strInprocess to an empty string if there is no space in @strinput?
Thanks, I had narrowed it down to that line myself by debugging the hard way (replacing variables with fixed values one at a time). No I hadn't realised that if there were no space it would return an empty string. 99% of the strings will have a space and the ones I have tested have a space but I will have to correct for the 1%. Thanks for spotting that.
But I don't know what is wrong with the line. If I take the line out of the function and just enter in the query window like below, it works fine returning 'Hello':
SELECT rtrim(LEFT('Hello Moto',CHARINDEX(' ','Hello Moto')))
Lack of a debugger is a pain.