We’ve got a longstanding function that writes the results of a query to a file. This works great. However, now I’m tasked with writing the result of a function to a file The function returns a dataset based on some input parameters. When run by itself in a Query window, results are returned in the Result Pane. But when passed to our “CreateFile” function, a blank file is written (if the return code is trapped).
EXECUTE LoanStatusChangeTracking '2011-5-26','2011-5-27','44000'
returns 65 rows for today.
DECLARE @Query varchar(MAX)
set @Query = 'EXECUTE [BankA].[dbo].[LoanStatusChangeTracking] ''2011-5-26'',''2011-5-27'',''44000'' '
Exec dbo.Ufn_CreateFile @Query, 'Collections2011-5-27.csv', 'S:\FTPTransferDaily', 'lms_user', 'kkoi8333323', '172.25.200.71', default
Doesn’t return anything or create a file. I can run it with a simple sql script and results get written.
What would be a likely place to start investigation?
The problem is due to temp tables. They don’t last, of course, and by the time the Create File function ran, there wasn’t anything to write to disk.