Is it possible to create a CSV file from a stored procedure?
I need to create a CSV file with data from a table, that is retrieved in a stored procedure
Is it possible to create a CSV file from a stored procedure?
I need to create a CSV file with data from a table, that is retrieved in a stored procedure
I got this to work on a simple Stored Procedure, replace "YourDatabase.dbo.YourSproc"
DECLARE @string AS NVARCHAR(4000)
SELECT @string = 'BCP "exec YourDatabase.dbo.YourSproc" QUERYOUT c:\data.csv -c -T -t'
exec master.dbo.xp_cmdshell @string
The only way I really see this possible is, in the stored procedure, have a call to xp_cmdshell
to execute bcp
with the parameters you are looking for. Not sure of any other way to do that.