SELECT INTO ステートメント
SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。
SQL クエリを使ったデータのエクスポート
次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。
SELECT Id, Email INTO [csv://Leads.txt] FROM [Leads] WHERE Email = '[email protected]'ファイルURI で他のフォーマットを指定できます。利用可能な区切り文字はタブ、セミコロン、カンマです。デフォルトはカンマです。次の例は、tab-separated values(TSV)にエクスポートします。
SELECT Id, Email INTO [csv://Leads.txt;delimiter=tab] FROM [Leads] WHERE Email = '[email protected]'
C#
String connectionString = "Schema=REST;RESTEndpoint=https://MyMarketoUrl/rest;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;";
using (MarketoConnection connection = new MarketoConnection(connectionString)) {
MarketoCommand cmd = new MarketoCommand("SELECT Id, Email INTO [csv://Leads.txt] FROM [Leads] WHERE Email = '[email protected]' ", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "Schema=REST;RESTEndpoint=https://MyMarketoUrl/rest;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;"
Using connection As New MarketoConnection(connectionString)
Dim cmd As New MarketoCommand("SELECT Id, Email INTO [csv://Leads.txt] FROM [Leads] WHERE Email = '[email protected]'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。
C#
String connectionString = "Schema=REST;RESTEndpoint=https://MyMarketoUrl/rest;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;";
using (MarketoConnection connection = new MarketoConnection(connectionString)) {
MarketoCommand cmd = new MarketoCommand("SELECT * INTO [Leads] IN [csv://filename=c:/Leads.csv;delimiter=tab] FROM [Leads] WHERE Email = '[email protected]'", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "Schema=REST;RESTEndpoint=https://MyMarketoUrl/rest;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;"
Using connection As New MarketoConnection(connectionString)
Dim cmd As New MarketoCommand("SELECT * INTO [Leads] IN [csv://filename=c:/Leads.csv;delimiter=tab] FROM [Leads] WHERE Email = '[email protected]'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using