ODBC Driver for OData

Build 20.0.7654

SELECT INTO ステートメント

SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。

SQL クエリを使ったデータのエクスポート

次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。

SELECT Id, FullName INTO [csv://Lead.txt] FROM [Lead] WHERE FirstName = 'Bartholomew'
ファイルURI で他のフォーマットを指定できます。利用可能な区切り文字はタブ、セミコロン、カンマです。デフォルトはカンマです。次の例は、tab-separated values(TSV)にエクスポートします。
SELECT Id, FullName INTO [csv://Lead.txt;delimiter=tab] FROM [Lead] WHERE FirstName = 'Bartholomew'

C#

String connectionString = "User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;";

using (ODataConnection connection = new ODataConnection(connectionString)) {
  ODataCommand cmd = new ODataCommand("SELECT Id, FullName INTO [csv://Lead.txt] FROM [Lead] WHERE FirstName = 'Bartholomew' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;" 

Using connection As New ODataConnection(connectionString)
  Dim cmd As New ODataCommand("SELECT Id, FullName INTO [csv://Lead.txt] FROM [Lead] WHERE FirstName = 'Bartholomew'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。

C#

String connectionString = "User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;";

using (ODataConnection connection = new ODataConnection(connectionString)) {
  ODataCommand cmd = new ODataCommand("SELECT * INTO [Lead] IN [csv://filename=c:/Lead.csv;delimiter=tab] FROM [Lead] WHERE FirstName <> 'Bartholomew'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;" 

Using connection As New ODataConnection(connectionString)
  Dim cmd As New ODataCommand("SELECT * INTO [Lead] IN [csv://filename=c:/Lead.csv;delimiter=tab] FROM [Lead] WHERE FirstName <> 'Bartholomew'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

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