Cmdlets for IBM Cloud SQL Query

Build 20.0.7654

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):

C#

String connectionString = "Api Key=MyAPIKey;";

using (IBMCloudSQLQueryConnection connection = new IBMCloudSQLQueryConnection(connectionString)) {
  IBMCloudSQLQueryCommand cmd = new IBMCloudSQLQueryCommand("SELECT Id, Status INTO [csv://Jobs.txt] FROM [Jobs] WHERE UserId = 'gentit@cdata.com' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "Api Key=MyAPIKey;" 

Using connection As New IBMCloudSQLQueryConnection(connectionString)
  Dim cmd As New IBMCloudSQLQueryCommand("SELECT Id, Status INTO [csv://Jobs.txt] FROM [Jobs] WHERE UserId = 'gentit@cdata.com'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
You can specify other file formats in the URI. The following example exports tab-separated values:

C#

String connectionString = "Api Key=MyAPIKey;";

using (IBMCloudSQLQueryConnection connection = new IBMCloudSQLQueryConnection(connectionString)) {
  IBMCloudSQLQueryCommand cmd = new IBMCloudSQLQueryCommand("SELECT * INTO [Jobs] IN [csv://filename=c:/Jobs.csv;delimiter=tab] FROM [Jobs] WHERE UserId = 'gentit@cdata.com'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "Api Key=MyAPIKey;" 

Using connection As New IBMCloudSQLQueryConnection(connectionString)
  Dim cmd As New IBMCloudSQLQueryCommand("SELECT * INTO [Jobs] IN [csv://filename=c:/Jobs.csv;delimiter=tab] FROM [Jobs] WHERE UserId = 'gentit@cdata.com'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7654