SELECT INTO ステートメント
SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。
SQL クエリを使ったデータのエクスポート
次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。
C#
String connectionString = "User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/";
using (SAPGatewayConnection connection = new SAPGatewayConnection(connectionString)) {
SAPGatewayCommand cmd = new SAPGatewayCommand("SELECT Id, Column1 INTO [csv://SampleTable_1.txt] FROM [SampleTable_1] WHERE Column2 = 'Bob' ", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/"
Using connection As New SAPGatewayConnection(connectionString)
Dim cmd As New SAPGatewayCommand("SELECT Id, Column1 INTO [csv://SampleTable_1.txt] FROM [SampleTable_1] WHERE Column2 = 'Bob'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。
C#
String connectionString = "User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/";
using (SAPGatewayConnection connection = new SAPGatewayConnection(connectionString)) {
SAPGatewayCommand cmd = new SAPGatewayCommand("SELECT * INTO [SampleTable_1] IN [csv://filename=c:/SampleTable_1.csv;delimiter=tab] FROM [SampleTable_1] WHERE Column2 = 'Bob'", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/"
Using connection As New SAPGatewayConnection(connectionString)
Dim cmd As New SAPGatewayCommand("SELECT * INTO [SampleTable_1] IN [csv://filename=c:/SampleTable_1.csv;delimiter=tab] FROM [SampleTable_1] WHERE Column2 = 'Bob'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using