I have a SQL code like shown below:
declare @str nvarchar(max),@i int set @i=0 set @str='abc ' declare @tbl Table(a nvarchar(max)) insert @tbl select @str while (select a from @tbl)<>'' begin set @i=@i+1 set @str = substring(@str,2,len(@str)) update @tbl set a=@str select * from @tbl end
@str has value
'abc ' (there is a space at the end). When above query is executed it will stop when only a space is present in
Also output of this query is:
bc c <here blank>
For the above query if I give input
then output will be
bcd cd d <here blank>
So in the first case that is
@str='abc ' I want to get output like
bc c <here blank> <here blank>
Now the code is checking for space and because of that I am having problem. But I want it to consider the space at the end also.
Same is the problem in SQL for
len() also. Both
len('a ') will return 1.
So if anyone please help on my query so that it will give my desired output.