Escape it with ^&Set @WriteLine = REPLACE(REPLACE( 'echo ' + @DEST_SORTCODE + @DEST_ACCOUNTNUMBER + @TRANSACTIONCODE + @ORIG_SORTCODE + '0000' + @TRANSACTIONVALUE + @ORIG_ACCOUNTNAME + @DEST_BANKREFERENCE + @DEST_ACCOUNTNAME + ' >> ' + @FileName , '^', '^^') , '&', '^&')
that will also take care of the unlikely situation that you have "^&" in your data stream too ...Add more REPLACE for any other characters that need escaping