[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using QODBC

Posted on 2014-03-18
3
Medium Priority
?
627 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

650 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