Have a look at this:
In your case, you may want to adapt it slightly to match your KeyID with image name, but it should get you started.
Also check if you can implement a SSIS solution instead.
Also refer to forum post:
http://www.sqlservercentral.com/Forums/Topic1066764-391-1.aspx
HTH,
B