The full stored procedure is quite lengthy, I have reduced it down to the following:
declare@DaysSMALLINT
declare @FilePathNVARCHAR(20)
Declare @OutputNVARCHAR(160)
SET @Days = -2
SET @FilePath = 'C:\SAPExport.txt'
SELECT @output = AFC.dbo.OITM.ItemCode
FROM AFC.dbo.OITM
INNER JOIN AFC.dbo.ITM1...