+ Reply to Thread
Results 1 to 6 of 6

Importing data from Access to Excel using SQL statements causes numbers to change. Why?

  1. #1
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Importing data from Access to Excel using SQL statements causes numbers to change. Why?

    Using SQL select statements I import data from an Access table into Excel.
    The field size in Access = single. All the numbers only have 2 decimal places, however, when they are imported to Excel they end up being any number of decimal places.


    For example:

    6.93 comes out as 6.929999999993

    Is there any explanation for this behaviour?

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Importing data from Access to Excel using SQL statements causes numbers to change. Why

    I'm guessing it's caused by floating point precision.

    Basically, many numbers can't be accurately represented by binary within limited amount of binary digits.
    Ex: Floating point approximation of 0.1 can be slightly greater than or less than 0.1

    Have a read of links.
    https://docs.oracle.com/cd/E19957-01..._goldberg.html
    https://support.microsoft.com/en-us/...g-point-errors
    http://www.exploringbinary.com/why-0...loating-point/
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Importing data from Access to Excel using SQL statements causes numbers to change. Why

    Its also possible they are only formatted as 2 decimal places in what you see in the database but that the underlying data is more precise and Excel is just displaying the precision.

    Do all the numbers show the same symptoms or only some?

    Is it viable to just format them in Excel to show 2 decimals and/or to use a formula to round/truncate them?

  4. #4
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Importing data from Access to Excel using SQL statements causes numbers to change. Why

    Prior to the numbers going into the Access table they are rounded to 2 decimal places, therefore, there should be no reason that they would show as anything other than a number with 2 decimal places.

    All of the numbers show the same symptom. 26 columns with numbers and all show the same symptom when imported into Excel.


    All of the numbers are test scores between 0.00 and 99.99 so I have converted them to whole numbers using Int(number*100).

    I did some reading this morning and my understanding now is that it has something to do with the field length being single and in the process of importing the numbers are converted to double. Or perhaps I misunderstood? It would be useful to read some sort of explanation.

  5. #5
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Importing data from Access to Excel using SQL statements causes numbers to change. Why

    That sounds about right. And is related to floating point conversion.
    Basically, 6.93 actually has value of 6.929999828... stored in float, since it can't be converted to binary accurately.
    That's the likely culprit.

    In below example I've created table with 3 types.
    Single = Number, Single, Decimal places 2
    Double = Number, Double, Decimal places auto
    Decimal = Number, Decimal, Precision 18, Scale 10.

    Entered 6.93 in each of the field and queried using ADO into Excel.

    Simple query without any conversion.
    Please Login or Register  to view this content.
    0.JPG
    Decimals added in Number format to show precision.

    One way to get around it. Is by using Format().
    Please Login or Register  to view this content.
    This will return 6.93 as is. But will be returned as text. You can then use Excel to convert text to numbers and 6.93 will be in the cell.

  6. #6
    Forum Contributor
    Join Date
    11-04-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    334

    Re: Importing data from Access to Excel using SQL statements causes numbers to change. Why

    Thanks for your explanations CK76, it has made things much clearer.
    I used the single field size to save space so that I could fit more data into the table.
    My understanding is that there is no difference between the space used by field size long and field size single so I will convert my numbers to long to save space and avoid the floating decimal point issue.


    Another suggestion that I came across to overcome the problem is using the Cstr and CDbl functions

    Please Login or Register  to view this content.
    .
    Last edited by anrichards22; 12-06-2017 at 06:14 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Importing Access Data into Excel Tab
    By certifydgangsta in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-17-2014, 11:02 AM
  2. Importing Excel Data into Access
    By NSTurk725 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2010, 11:23 AM
  3. Importing Access data into Excel
    By u123450 in forum Excel General
    Replies: 1
    Last Post: 05-19-2010, 05:40 PM
  4. Importing Data from Access to Excel
    By dnnr in forum Excel General
    Replies: 0
    Last Post: 08-06-2007, 05:22 PM
  5. Importing data into Excel from Access
    By Blondegirl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2006, 05:51 PM
  6. Importing data from Access to Excel, but I need to vary the table from Access
    By Liz L. in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2006, 09:15 PM
  7. [SOLVED] Importing Data from Access into Excel
    By vnvkatz in forum Excel General
    Replies: 3
    Last Post: 06-09-2005, 12:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1