ODBC Driver for Sage 50 UK

Build 22.0.8462

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 TradingAccountUUID, Name INTO [csv://TradingAccounts.txt] FROM [TradingAccounts] WHERE TradingAccountUUID = 'c2ef66a5-a545-413b-9312-79a53caadbc4'
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 TradingAccountUUID, Name INTO [csv://TradingAccounts.txt;delimiter=tab] FROM [TradingAccounts] WHERE TradingAccountUUID = 'c2ef66a5-a545-413b-9312-79a53caadbc4'

C#

String connectionString = "URL=http://localhost:5493/sdata/accounts50/GCRM/{C4C863BE-B098-4A7D-A78B-D7A92B8ADB59};User=Manager;Password=xxxxxx;";

using (Sage50UKConnection connection = new Sage50UKConnection(connectionString)) {
  Sage50UKCommand cmd = new Sage50UKCommand("SELECT TradingAccountUUID, Name INTO [csv://TradingAccounts.txt] FROM [TradingAccounts] WHERE TradingAccountUUID = 'c2ef66a5-a545-413b-9312-79a53caadbc4' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "URL=http://localhost:5493/sdata/accounts50/GCRM/{C4C863BE-B098-4A7D-A78B-D7A92B8ADB59};User=Manager;Password=xxxxxx;" 

Using connection As New Sage50UKConnection(connectionString)
  Dim cmd As New Sage50UKCommand("SELECT TradingAccountUUID, Name INTO [csv://TradingAccounts.txt] FROM [TradingAccounts] WHERE TradingAccountUUID = 'c2ef66a5-a545-413b-9312-79a53caadbc4'", 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 = "URL=http://localhost:5493/sdata/accounts50/GCRM/{C4C863BE-B098-4A7D-A78B-D7A92B8ADB59};User=Manager;Password=xxxxxx;";

using (Sage50UKConnection connection = new Sage50UKConnection(connectionString)) {
  Sage50UKCommand cmd = new Sage50UKCommand("SELECT * INTO [TradingAccounts] IN [csv://filename=c:/TradingAccounts.csv;delimiter=tab] FROM [TradingAccounts] WHERE TradingAccountUUID = 'c2ef66a5-a545-413b-9312-79a53caadbc4'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "URL=http://localhost:5493/sdata/accounts50/GCRM/{C4C863BE-B098-4A7D-A78B-D7A92B8ADB59};User=Manager;Password=xxxxxx;" 

Using connection As New Sage50UKConnection(connectionString)
  Dim cmd As New Sage50UKCommand("SELECT * INTO [TradingAccounts] IN [csv://filename=c:/TradingAccounts.csv;delimiter=tab] FROM [TradingAccounts] WHERE TradingAccountUUID = 'c2ef66a5-a545-413b-9312-79a53caadbc4'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462