?
Solved

Using QODBC

Posted on 2014-03-18
3
Medium Priority
?
619 Views
Last Modified: 2014-03-19
I want to use QODBC; I have a couple of (I think) fairly simple requirements.

(1) Using a csv file imported from elsewhere, either create a new customer record or update an existing one; one row in csv file per customer.

(2) Export a large portion of (specific fields) of the customer table to a csv file.

(3) Ditto to (2) for Invoice & Invoiceline.

Can someone point me to examples that are similar or close to this?

Thanks
0
Comment
Question by:Richard Korts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Bill Bach earned 2000 total points
ID: 39939686
1) I do not believe that QODBC has an UPSERT command.  This means that you will need to build some logic into your environment to detect whether a customer already exists, then decide to use either an INSERT or an UPDATE statement, accordingly.  This is not too difficult with a VBScript program that reads a line from your CSV file, checks if the record exists first, then branches as needed.  This could look like this:
	ExistingCust = "SELECT TOP 1 ListID FROM Customer WHERE Name = '" & NameFromCSV & "'
	Set FoundName = conn.Execute(ExistingCust)
	if not FoundName.EOF then

Open in new window


Once you branch, the INSERT and UPDATE statements are standard SQL, and the examples from the QODBC documentation should suffice.  

2) Exporting data is easy.  A simple SQL Statement like "SELECT * FROM Customer" will give you all of the fields.  If you want to export it to CSV, then you can use a GUI tool like MSAccess or MSExcel to read and export the data, or you can use a command line tool like SQLExec like this:  SQLEXEC "QuickBooksData" "Select * from Customer Order By Name" /oc

In my own use of QODBC, I use this statement to export my customer data:

SELECT Customer.FullName, Customer.Contact, Customer.Phone, Customer.EMail, Customer.BillAddressCity, Customer.BillAddressState, Customer.BillAddressAddr1, Customer.BillAddressAddr2, Customer.BillAddressAddr3, Customer.BillAddressAddr4, Customer.BillAddressPostalCode, Customer.BillAddressCountry
FROM Customer NOSYNC
WHERE (Customer.CustomerTypeRefFullName<>'CLOSED')
ORDER BY Customer.CompanyName

Obviously, you can add fields that you need or remove those that you do not.

3) Exports for these are the same -- simple select statements via any ODBC-compatible tool.  Again, I do these nightly via an automated SQLExec script that dumps my data into a second database which allows for faster searches, and I use a query like this:

SELECT 
	Invoice.RefNumber,
	Invoice.TxnDate,
	Invoice.PONumber,
	Invoice.CustomerRefFullName,
	Invoice.SubTotal,
	Invoice.BalanceRemaining,
	Invoice.BillAddressAddr1,
	Invoice.BillAddressAddr2,
	Invoice.BillAddressAddr3,
	Invoice.BillAddressAddr4,
	Invoice.BillAddressCity,
	Invoice.BillAddressState,
	Invoice.BillAddressPostalCode,
	Invoice.BillAddressCountry,
	Invoice.ShipAddressAddr1,
	Invoice.ShipAddressAddr2,
	Invoice.ShipAddressAddr3,
	Invoice.ShipAddressAddr4,
	Invoice.ShipAddressCity,
	Invoice.ShipAddressState,
	Invoice.ShipAddressPostalCode,
	Invoice.ShipAddressCountry,
	Invoice.SalesTaxTotal
FROM 
        Invoice NOSYNC
WHERE
	{fn TIMESTAMPDIFF(SQL_TSI_DAY, Invoice.TxnDate, {fn CURDATE()})} < 30
ORDER BY 
	Invoice.RefNumber;

SELECT 
	InvoiceLine.RefNumber,
	InvoiceLine.InvoiceLineSeqNo,
	InvoiceLine.InvoiceLineQuantity,
	InvoiceLine.InvoiceLineItemRefFullName,
	InvoiceLine.InvoiceLineDesc,
	InvoiceLine.InvoiceLineRate,
	InvoiceLine.InvoiceLineAmount
FROM 
        InvoiceLine NOSYNC
WHERE 
	{fn TIMESTAMPDIFF(SQL_TSI_DAY, InvoiceLine.TxnDate, {fn CURDATE()})} < 30
ORDER BY 
	InvoiceLine.RefNumber;

Open in new window


Note that these queries grab the last 30 days of invoices, because I assume that we are not changing anything older than 30 days back.  Also, notice the use of NOSYNC because I force a synchronization of the QODBC cache immediately before my scripts run by calling "sp_optimizeupdatesync Invoice" first.
0
 

Author Comment

by:Richard Korts
ID: 39939743
Thanks a lot; I meant INSERT (just standard SQL), that was a typo.

Rkorts
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 39939756
Actually, "UPSERT" is a command in some environments, especially ETL tools.  It means "UPDATE the record if it exists, or INSERT the record if it does not exist".  It greatly simplifies the work of loading data from an import file.  Without this feature, you have to do the heavy lifting yourself in code.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question