1
I need to somehow export the result of my SQL query to a CSV file. However, it has to be directly via SQL or VBS.
Or else, all database table data can be exported to CSV.
1
I need to somehow export the result of my SQL query to a CSV file. However, it has to be directly via SQL or VBS.
Or else, all database table data can be exported to CSV.
3
The utility BCP makes it possible to export data to text file, CSV format. Through the -t option it is possible to define the field separator. I recommend the previous reading of the document Specify field and line terminators.
It is also possible to use the function OPENROWSET to export.
Some articles on the subject:
2
I was able to export from SQL Server to CSV via the code below:
exec master..xp_cmdshell 'bcp "Select E3TimeStamp, Message, USUARIO, Acked, Severity, FormattedValue, Area, EventType From [c1_alarmes].[dbo].[table_alarmes]" queryout D:\bcp_outputTable.CSV -c -t; -T -S localhost\Testes'
It generated the CVS file after enabling xp_cmdshell via the command:
exec sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
A question I still have, in the generated file does not show the name of each column. If someone knows how to add this in generation.
Browser other questions tagged sql database sql-server vbs
You are not signed in. Login or sign up in order to post.
But I needed to do just that through code.
– Agnaldo Junior