+ Reply to Thread
Results 1 to 7 of 7

Import excel to MSSQL converts long numbers to +000

  1. #1
    Forum Contributor
    Join Date
    05-28-2010
    Location
    Antwerp, Belgium
    MS-Off Ver
    Office 365
    Posts
    170

    Import excel to MSSQL converts long numbers to +000

    I am importing an excel file to MSSQL with the following script:

    SELECT * INTO Z_StockImport
    FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0',
    'Data Source=\\path\StockList.xls;Extended Properties=Excel 12.0')...[StockList$];
    GO


    The problem is that one of the columns has very long numbers, but they have to stay this way, so instead of the original value: 2185693631 it changes to: 2.18569e+009

    It's some automatic mechanism, so I cannot do changes on the excel before importing it.. how can I specify during the import to keep the value as is OR how to update in the MSSQL afterwards that it will change back to the original number?

    Thanks

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Import excel to MSSQL converts long numbers to +000

    Sometimes, Excel will "help" you by converting long numbers to scientific notation simply because the column is too narrow to show the number. With almost any other kind of data, it will show #######, but if it is a string of numbers, it sometimes converts it to scientific notation. Try formatting the column with the number to text.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor
    Join Date
    05-28-2010
    Location
    Antwerp, Belgium
    MS-Off Ver
    Office 365
    Posts
    170

    Re: Import excel to MSSQL converts long numbers to +000

    Quote Originally Posted by dflak View Post
    Sometimes, Excel will "help" you by converting long numbers to scientific notation simply because the column is too narrow to show the number. With almost any other kind of data, it will show #######, but if it is a string of numbers, it sometimes converts it to scientific notation. Try formatting the column with the number to text.
    Thanks for the reply, but did you read my question?

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

    Re: Import excel to MSSQL converts long numbers to +000

    Quote Originally Posted by whatever61 View Post
    It's some automatic mechanism, so I cannot do changes on the excel before importing it.. how can I specify during the import to keep the value as is OR how to update in the MSSQL afterwards that it will change back to the original number?
    Quote Originally Posted by whatever61 View Post
    Thanks for the reply, but did you read my question?
    The answer to your question specifically is "you dont". dflak was trying to explain why to you.

    Excel interprets numbers differently then most other systems. Most databases do not distinguish (in exports at least) between numbers and text (ie: "1" or 1). Therefor Excel interprets what it thinks the values should be (numeric or text).

    What you are seeing is scientific notation, its just a shorter way of writing a large (or really small) number. Since its Excel deciding to represent it this way it doesnt matter what you do before that data is processed by Excel as it will still interpret the numeric value. Its possible you may get it to decide its text, in which case you have a new set of considerations/issues.

    Another thing to consider is Excel can only handle a certain number of digits of significance, I think 15, after which point it truncates the rest placing 0's at the end (right most) of the number. So if these numbers are > 15 digits, nothing you do other than storing them as text will keep the value unchanged.

    So in ending, you either export in a different format (possibly native export to Excel in which case the system exporting determines how to feed the values to the sheet, or different file format) or you format it after its imported into Excel.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  5. #5
    Forum Contributor
    Join Date
    05-28-2010
    Location
    Antwerp, Belgium
    MS-Off Ver
    Office 365
    Posts
    170

    Re: Import excel to MSSQL converts long numbers to +000

    Quote Originally Posted by Zer0Cool View Post
    The answer to your question specifically is "you dont". dflak was trying to explain why to you.

    Excel interprets numbers differently then most other systems. Most databases do not distinguish (in exports at least) between numbers and text (ie: "1" or 1). Therefor Excel interprets what it thinks the values should be (numeric or text).

    What you are seeing is scientific notation, its just a shorter way of writing a large (or really small) number. Since its Excel deciding to represent it this way it doesnt matter what you do before that data is processed by Excel as it will still interpret the numeric value. Its possible you may get it to decide its text, in which case you have a new set of considerations/issues.

    Another thing to consider is Excel can only handle a certain number of digits of significance, I think 15, after which point it truncates the rest placing 0's at the end (right most) of the number. So if these numbers are > 15 digits, nothing you do other than storing them as text will keep the value unchanged.

    So in ending, you either export in a different format (possibly native export to Excel in which case the system exporting determines how to feed the values to the sheet, or different file format) or you format it after its imported into Excel.
    I know what scientific notation is. That wasn't my question neither.
    In the excel file it shows it properly (not as a scientific notation, but as a number) . When I am importing it to MSSQL through the script I wrote above IN THE MSSQL table it will convert it to scientific notion, while I want to keep it as a number.

    Maybe if I would change it to TEXT and then import it, it would be ok, however it's an automatic mechanism that downloads an excel file from somewhere and then imports it daily. So I cannot do changes in the excel before importing it..

    Hope it's clearer!

    Thanks

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

    Re: Import excel to MSSQL converts long numbers to +000

    Ah ok, so your asking in an Excel specific forum how something works in MSSQL.

  7. #7
    Forum Contributor
    Join Date
    05-28-2010
    Location
    Antwerp, Belgium
    MS-Off Ver
    Office 365
    Posts
    170

    Re: Import excel to MSSQL converts long numbers to +000

    Quote Originally Posted by Zer0Cool View Post
    Ah ok, so your asking in an Excel specific forum how something works in MSSQL.
    I really don't get your comment, it says it right in the title and in the first line of my post..

    I am trying to import an excel file after all, so someone could know about this stuff here also.

+ 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. Excel automatically converts numbers to a date
    By rinconmike in forum Excel General
    Replies: 3
    Last Post: 04-15-2014, 02:24 PM
  2. Replies: 4
    Last Post: 10-09-2013, 12:30 AM
  3. Google Earth lat./long. import to Excel
    By PCAg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2012, 10:47 AM
  4. [SOLVED] Import text file from Excel converts cell value into scientific notation in error
    By maacmaac in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-24-2012, 02:03 PM
  5. Excel cannot import files with long column and with comma
    By samart103 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2010, 03:15 PM
  6. converts numbers to dates
    By jason2444 in forum Excel General
    Replies: 2
    Last Post: 02-10-2006, 06:45 PM
  7. VB.net/Excel/MSSQL Solution - Help!
    By ColinNOVO in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2005, 08:05 AM
  8. [SOLVED] Text file import using ADO - XL converts fields to dates
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2005, 11:05 AM

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