SELECT INTO Statements
You can use the SELECT INTO statement to export formatted data to a file.
Data Export with an SQL Query
The following query exports data into a file formatted in comma-separated values (CSV):
SELECT Price, Name INTO [csv://Products.txt] FROM [Products] WHERE EntityId = '238'You can specify other formats in the file URI. The possible delimiters are tab, semicolon, and comma with the default being a comma. The following example exports tab-separated values:
SELECT Price, Name INTO [csv://Products.txt;delimiter=tab] FROM [Products] WHERE EntityId = '238'
C#
String connectionString = "User=admin;Password=admin;Url=https://mymagentohost/magento2"; using (MagentoConnection connection = new MagentoConnection(connectionString)) { MagentoCommand cmd = new MagentoCommand("SELECT Price, Name INTO [csv://Products.txt] FROM [Products] WHERE EntityId = '238' ", connection); int rowsAffected = cmd.ExecuteNonQuery(); }
VB.NET
Dim connectionString As [String] = "User=admin;Password=admin;Url=https://mymagentohost/magento2" Using connection As New MagentoConnection(connectionString) Dim cmd As New MagentoCommand("SELECT Price, Name INTO [csv://Products.txt] FROM [Products] WHERE EntityId = '238'", connection) Dim rowsAffected As Integer = cmd.ExecuteNonQuery() End UsingYou can specify other file formats in the URI. The following example exports tab-separated values:
C#
String connectionString = "User=admin;Password=admin;Url=https://mymagentohost/magento2"; using (MagentoConnection connection = new MagentoConnection(connectionString)) { MagentoCommand cmd = new MagentoCommand("SELECT * INTO [Products] IN [csv://filename=c:/Products.csv;delimiter=tab] FROM [Products] WHERE EntityId = '238'", connection); int rowsAffected = cmd.ExecuteNonQuery(); }
VB.NET
Dim connectionString As [String] = "User=admin;Password=admin;Url=https://mymagentohost/magento2" Using connection As New MagentoConnection(connectionString) Dim cmd As New MagentoCommand("SELECT * INTO [Products] IN [csv://filename=c:/Products.csv;delimiter=tab] FROM [Products] WHERE EntityId = '238'", connection) Dim rowsAffected As Integer = cmd.ExecuteNonQuery() End Using