CLOSE tables clear m.fstr = conver_to_hex(FILETOSTR(GETFILE())) m.pstr = putfile() han = SQLCONNECT('A') m.lcsql = [CREATE TABLE ##foo1 (f1 Varbinary(max) )] SQLEXEC(han,m.lcsql) lcsql = [insert into ##foo1 (f1) values ( ]+m.fstr+[)] SQLEXEC(han,lcsql) lcsql = [DECLARE @SQLcommand varchar(1000) ]+; [set @SQLcommand = 'bcp "SELECT f1 FROM ##foo1 " queryout "]+pstr+[" -f"c:\test\image.fmt" -T -SNAGAVENI\SQLEXPRESS ' ]+; [exec xp_cmdshell @SQLcommand] SQLEXEC(han,lcsql) SQLDISCONNECT(han) procedure conver_to_hex LPARAMETERS tcstring LOCAL lcstring lcstring = '0x' FOR m.xi = 1 TO LEN(tcstring) lcstring = lcstring + strtran(TRANSFORM(ASC(SUBSTR(tcstring,m.xi,1)) ,'@0'),'0x000000','') endfor RETURN lcstringAnd a image.fmt is