just to let you know. I did try the sql statement that you posted and it still didn't work.
I could get the script woking with a static list from the example, but when I changed things to use the sql it won't work.