Skip to content
Advertisement

SQL Server export image to hardisc by iterating through fieldnames

We receive 10 images in varchar format through a mobile device app which are stored in one record of a table. The fields where the images are imported are named ImportPictureData, ImportPictureData2,…

more of the importfields could be added.

To make the export flexible, I read the fieldnames in a table variable and try to create a dynamic SQL for the loop through the fields.

The SQL-string looks good where I create the string and print it(!) and then I try to assign the string to the variable which should recieve the image data:

creates this string:

When I assign this string as a hardcopy to the variable @ImageData I do not get any error, if I am going to assign the variable @sqlDynamicString to the variable @ImageData like

I get an

what is going wrong here?? Even using convert iso cast I get the same error.

Thanks

Advertisement

Answer

Execute the code in @sqlDynamicString,store the result in a temp table and then assign to your varbinary variable.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement