I have just upgraded a system from 2008 R2 to 2012 SP1.
I have an issue with a scheduled SP that fails 'randomly' whilst processing/emailing a series of files created by a previous SP.
The SP gets a directory list and processes each file. The processing involves issuing a 'move' command via XP_cmdshell and then adds the filename to a variable.
At the end of the SP, the list of files is used as an attahement list to a mail command.
The problem is that the first move works, then when the next file is moved I get a failure reported (SOMETIMES).
The actual failure is: Incorrect syntax near 'Begi'. [SQLSTATE 42000] (Error 102).
I thought I had fixed it by inserting some 'debugging' select statements - but the problem came back.
The call to xp_cmdshell is of the form 'move "filename and directory 1" "filenname and directory 2". After investigation it appears that more than one set of double quotes *may* have some bearing on the issue and I can resolve it by removing all the double quotes (no imbedded spaces in filenames so I am OK).
Before I remove the quotes however, I would be interested if anyone can shed any light on the 'randomness' of the issue - it doesn't always occur and the adding of simple "Select 'AT Step x' " type debugging statements (with output to file and log output turned on in SQL Server agent job) appears to sometimes fix the issue.
Stan