SOLVED

stored procedure to fetch image data from sql server 2005 and save to file

%3CLINGO-SUB%20id%3D%22lingo-sub-1552472%22%20slang%3D%22en-US%22%3Estored%20procedure%20to%20fetch%20image%20data%20from%20sql%20server%202005%20and%20save%20to%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1552472%22%20slang%3D%22en-US%22%3E%3CP%3Esyntax%20error%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22pln%22%3Eperty%20%40Obj%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Type'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22lit%22%3E1%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Open'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Write'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd3%22%3ENULL%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40ImageData%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'SaveToFile'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd3%22%3ENULL%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Path2OutFile%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22lit%22%3E2%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Close'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OADestroy%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEND%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20TRY%0A%20%20%20%20%0A%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EBEGIN%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20CATCH%0A%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OADestroy%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%3CSPAN%20class%3D%22kwd%22%3EEND%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20CATCH%0A%20%0A%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3ESET%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20NOCOUNT%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EOFF%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kwd%22%3EEND%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kwd%22%3EGO%3C%2FSPAN%3E%3C%2FPRE%3E%3CPRE%3E%3CSPAN%20class%3D%22kwd%22%3ECREATE%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd%22%3EPROCEDURE%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20dbo%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E.%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3Eusp_ExportImage%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%40PicName%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3ENVARCHAR%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22lit%22%3E100%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3C%2FSPAN%3E%0A%20%20%20%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%40ImageFolderPath%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3ENVARCHAR%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22lit%22%3E1000%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3C%2FSPAN%3E%0A%20%20%20%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%40Filename%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3ENVARCHAR%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22lit%22%3E1000%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3C%2FSPAN%3E%0A%20%20%20%3CSPAN%20class%3D%22pun%22%3E)%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kwd%22%3EAS%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kwd%22%3EBEGIN%3C%2FSPAN%3E%0A%20%20%20%3CSPAN%20class%3D%22kwd%22%3EDECLARE%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40ImageData%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EVARBINARY%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd2%22%3Emax%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%0A%20%20%20%3CSPAN%20class%3D%22kwd%22%3EDECLARE%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Path2OutFile%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3ENVARCHAR%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22lit%22%3E2000%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%0A%20%20%20%3CSPAN%20class%3D%22kwd%22%3EDECLARE%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Obj%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EINT%3C%2FSPAN%3E%0A%20%0A%20%20%20%3CSPAN%20class%3D%22kwd%22%3ESET%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20NOCOUNT%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EON%3C%2FSPAN%3E%0A%20%0A%20%20%20%3CSPAN%20class%3D%22kwd%22%3ESELECT%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40ImageData%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3ESELECT%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd2%22%3Econvert%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22typ%22%3EVARBINARY%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd2%22%3Emax%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20PictureData%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22lit%22%3E1%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EFROM%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20Pictures%0A%20%20%20%20%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EWHERE%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20pictureName%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40PicName%0A%20%20%20%20%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%0A%20%0A%20%20%20%3CSPAN%20class%3D%22kwd%22%3ESET%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Path2OutFile%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20CONCAT%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20%20%20%20%20%20%40ImageFolderPath%0A%20%20%20%20%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'%5C'%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Filename%0A%20%20%20%20%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EBEGIN%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20TRY%0A%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OACreate%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'ADODB.Stream'%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%40Obj%20OUTPUT%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OASetProperty%20%40Obj%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Type'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22lit%22%3E1%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Open'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Write'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd3%22%3ENULL%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40ImageData%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'SaveToFile'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22kwd3%22%3ENULL%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Path2OutFile%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22lit%22%3E2%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OAMethod%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'Close'%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OADestroy%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22kwd%22%3EEND%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20TRY%0A%20%20%20%20%0A%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EBEGIN%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20CATCH%0A%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EEXEC%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20sp_OADestroy%20%40Obj%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3B%3C%2FSPAN%3E%0A%20%3CSPAN%20class%3D%22kwd%22%3EEND%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20CATCH%0A%20%0A%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3ESET%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20NOCOUNT%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22kwd%22%3EOFF%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kwd%22%3EEND%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22kwd%22%3EGO%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1552477%22%20slang%3D%22en-US%22%3ERe%3A%20stored%20procedure%20to%20fetch%20image%20data%20from%20sql%20server%202005%20and%20save%20to%20file%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1552477%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F743285%22%20target%3D%22_blank%22%3E%40wasim_ahmad%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Echange%20the%20concatenation%20got%20syntax%20error%20near%20'%2C'%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22kwd%22%3ESET%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Path2OutFile%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%2B%22%20-%20%22%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%20%20%20%20%20%20%20%20%40ImageFolderPath%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FPRE%3E%3CPRE%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22str%22%3E'%5C'%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22pln%22%3E%20%40Filename%0A%20%20%20%20%20%20%20%20%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E)%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3CPRE%3E%3CSPAN%20class%3D%22pln%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

syntax error 

 

perty @Obj ,'Type',1;
     EXEC sp_OAMethod @Obj,'Open';
     EXEC sp_OAMethod @Obj,'Write', NULL, @ImageData;
     EXEC sp_OAMethod @Obj,'SaveToFile', NULL, @Path2OutFile, 2;
     EXEC sp_OAMethod @Obj,'Close';
     EXEC sp_OADestroy @Obj;
    END TRY
    
 BEGIN CATCH
  EXEC sp_OADestroy @Obj;
 END CATCH
 
   SET NOCOUNT OFF
END
GO
CREATE PROCEDURE dbo.usp_ExportImage (   @PicName NVARCHAR (100)
   ,@ImageFolderPath NVARCHAR(1000)
   ,@Filename NVARCHAR(1000)
   )
AS
BEGIN
   DECLARE @ImageData VARBINARY (max);
   DECLARE @Path2OutFile NVARCHAR (2000);
   DECLARE @Obj INT
 
   SET NOCOUNT ON
 
   SELECT @ImageData = (
         SELECT convert (VARBINARY (max), PictureData, 1)
         FROM Pictures
         WHERE pictureName = @PicName
         );
 
   SET @Path2OutFile = CONCAT (         @ImageFolderPath
         ,'\'
         , @Filename
         );
    BEGIN TRY
     EXEC sp_OACreate 'ADODB.Stream' ,@Obj OUTPUT;
     EXEC sp_OASetProperty @Obj ,'Type',1;
     EXEC sp_OAMethod @Obj,'Open';
     EXEC sp_OAMethod @Obj,'Write', NULL, @ImageData;
     EXEC sp_OAMethod @Obj,'SaveToFile', NULL, @Path2OutFile, 2;
     EXEC sp_OAMethod @Obj,'Close';
     EXEC sp_OADestroy @Obj;
    END TRY
    
 BEGIN CATCH
  EXEC sp_OADestroy @Obj;
 END CATCH
 
   SET NOCOUNT OFF
END
GO

 

1 Reply
best response confirmed by wasim_ahmad (New Contributor)
Solution

@wasim_ahmad 

change the concatenation got syntax error near ','

SET @Path2OutFile =  +" - "(         @ImageFolderPath
,'\'
         , @Filename
         );