Entrambi questi metodi funzionano.
Ma qual è la pratica migliore in un ambiente DEV / INT / QA? Comando SP o CMD?
--method 1
DECLARE @OLE INT
DECLARE @FileID INT
EXECUTE sp_OACreate 'Scripting.FileSystemObject', @OLE OUT
EXECUTE sp_OAMethod @OLE, 'OpenTextFile', @FileID OUT, 'C:\TempTableData.txt', 8, 1
EXECUTE sp_OAMethod @FileID, 'WriteLine', Null, 'testing testing \n testing'
EXECUTE sp_OADestroy @FileID
EXECUTE sp_OADestroy @OLE
--method 2
DECLARE @Text AS VARCHAR(100)
DECLARE @Cmd AS VARCHAR(100)
SET @Text = 'Hello world^| '
SET @Cmd ='echo ' + @Text + ' > C:\TempTableData.txt'
EXECUTE Master.dbo.xp_CmdShell @Cmd