Thanks Jon for being patient with me so far. Really appreciate your help.
I've tried putting it into array and then slice it afterwards, It ran all fine this time. However, the iValue column is still not updated to 1.
The trouble here is - This statement " if ((res.@content + '').length > 160)" is resulting length zero (0), hence the complete if condition is not getting executed as its checking for > 160. Is it because of res.@content is not getting stored in query result variable as its an XML field?