Search code examples
sqlexcelsql-import-wizard

Importing numbers with leading zeros from excel into SQL Server Management Studio


I am trying to import numbers (postcodes) into a SQL DB using the SQL Server Import and Export Wizard. The column is text in Excel however when I import the file, the postcode column gets mapped to a float type which is causing NULL results for any values with a leading zero.


Solution

  • I created a new column and used the excel TEXT function to reformat the postcodes.

    =TEXT(P2,"0000")
    

    Then I imported the file with the new column and the new postcode column had a default mapping to nvarchar(255).