Currently I have a stored procedure which takes information from my tables stores it in a temp table then writes that information to a dummy file and that file creates the final file. When I run the stored procedure from SQL server the file writes fine. Then when I try to run this stored procedure outside of SQL server the last file is written blank. I originally thought the problem was the stored procedure was not converting the dates correctly and therefore no information was being found. Upon further inspection I found my dummy file was not being written at all. Thus when the procedure tried to copy data from the dummy to the real nothing was there. Any one have an idea why this would not be working? Below is the code I believe relevant. If anything is unclear let me know. Sorry about the format of the code I tried making it look better to no avail.
Set @FILENAME ='C:\Users\MRUTLAND\Desktop\Accounting'+ @FilenamePart+'.csv'
SET @DummyFile='C:\Users\MRUTLAND\Desktop\Dummy.csv'
SELECT
@TotalRecs =ISNULL(Count(*),0)FROM TMP_TierTOAcct_Payroll
IF @TotalRecs= 0
BEGIN
--SET @Msg =
print'No Payroll Data exists for '+convert(varchar, @StartDate,101)+' to '+convert(varchar, @EndDate,101)
GoTo ErrorTran
END
-- copy data to dummy file. the data is stored in TMP_TierToMAS_GL
SET @Sql=' SELECT * FROM WFS_Demo1.dbo.TMP_TierTOAcct_Payroll'
SET @SQL='BCP "'+ @SQL+'" queryout "'+ @Dummyfile+'" -fexport.fmt -t"," -c -T'
print @sql
ExecMaster..xp_Cmdshell@SQL
-- move the data from dummy file to data file. So that the data file has both headers and data
set @sql='exec master..xp_cmdshell ''type '+@Dummyfile+'>> "'+@Filename+'"'''
exec(@sql)
--remove the dummy file
set @sql='exec master..xp_cmdshell ''del '+@Dummyfile+''''
exec(@sql)