You are still looping on not @error. I would go with a more modularized method rather than in-line. Read in the works into an array with a UDF first and then iterate through the array.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.