Introduction
The Dutch postcode table holds information about all postcodes known in the Netherlands. This is very useful when you want more information about a certain postcode, such as a geographic location or the town that belongs to a postcode. In this article we show what you can do with these postcodes.
Source of the Dutch postcode table
The source of Dutch postcodes is the Kadaster (the Dutch land registry). The Kadaster supplies so-called “BAG files” through its site. They hold information about homes and buildings: the postcode among other things, but also a lot more interesting data. You have to process these files first before you can use them. This is quite complicated, and in practice not doable. My advice is not to reinvent the wheel but to use a ready-made file. There are initiatives for the data extraction, but studying them takes a lot of time (time=money). I work with a paid version of the postcode table (address file) myself, which holds over 9 million addresses. With this data you can find the exact location of your customers, because the address with house number is unique. In short, every address is a unique record with extra information such as Lat/Lon, province, town, etc.
Say you have a customer record in the database of your ERP system, with a postcode and an address. With an INNER JOIN (a link, a kind of VLOOKUP) to the postcode table on postcode + house number + addition, you can find the record that belongs to it. Then you can take the coordinates from the postcode file. The great thing about this: you now know where in the Netherlands the customer is. You can show this data in Excel in Excel Maps, but also in PowerBI. I must say, this works brilliantly! If you use the 6-digit table you can also link coordinates, but they are less precise. For example, you can analyse in which areas of the Netherlands most of your customers are. Even more interesting may be where you have no customers yet!
How does the SQL postcode table work?
Every postcode, together with its minimum and maximum house number range, has its own row in the table. The X-Y coordinates, also called latitude/longitude, are useful too. I used an SQL Function to calculate the GeoLocation directly, as you can see in the SQL statement below.
The free postcode table has 471,993 rows in total, so it is quite a big table. With the attached SQL Script you can import all data into Microsoft SQL Server in one go. At the bottom of this post you find a download link, the SQL script. Note that this file is not up to date and is < 2010. My advice is to buy the newest postcode table from postcodestore. It costs 249 euros and gives you over 9 million up-to-date rows of data. The file is updated every month, so you can also buy a new file again later. The website also has tutorials on how to import the data.
If you know your way around SQL, you will of course know how to work with this data. I will soon publish an article about how to show the geographic data from a table with a postcode/house number, for example in Excel Maps or Power BI.
Creating the postcode table
Run the SQL below to create the postcode table. Then run the script in SQL Server to fill the table with postcodes.
CREATE TABLE [dbo].[REF_Postcode_NL]([id] [float] NULL,[postcode] [nvarchar](255) NULL,[postcode_id] [float] NULL,[pnum] [float] NULL,[pchar] [nvarchar](255) NULL,[minnumber] [float] NULL,[maxnumber] [float] NULL,[numbertype] [nvarchar](255) NULL,[street] [nvarchar](255) NULL,[city] [nvarchar](255) NULL,[city_id] [float] NULL,[municipality] [nvarchar](255) NULL,[municipality_id] [float] NULL,[province] [nvarchar](255) NULL,[province_code] [nvarchar](255) NULL,[lat] [float] NULL,[lon] [float] NULL,[rd_x] [float] NULL,[rd_y] [float] NULL,[location_detail] [nvarchar](255) NULL,[changed_date] [datetime] NULL,[geographypoint] AS ([geography]::STGeomFromText(((('POINT('+CONVERT([varchar](20),[lon],(0)))+' ')+CONVERT([varchar](20),[lat],(0)))+')',(4326)))) ON [PRIMARY]Enriching data with the postcode table in Excel
What you can do with the postcode table is show data on the map. For example, with the first four digits of the postcode you can show data from Excel on the map with Power Maps. Power Maps comes free with Excel from version 2013. In this article we discuss how to do this. That article has a number of practical examples with Excel and SQL.
Conclusion
The postcode table of the Netherlands is a useful table. You can use it to make data entry easier, to enrich data, or to show data on the map. To learn more about postcode tables and data analysis, read the other articles on this topic.
This article is part of a series:
- Part 1: Dutch postcode table + SQL Script for import
- Part 2: Splitting postcode ranges into single records
- Part 3: Enriching customer data with the postcode table
- Part 4: Visualising data with coordinates in Power BI
Frequently asked questions
Where do Dutch postcodes come from?
From the Kadaster (the Dutch land registry). It supplies the BAG files with all addresses and buildings. You have to process those files first before you can use them in a database.
How do I link a customer address to the postcode table?
With an INNER JOIN on postcode, house number and addition. Then you find, per customer, the row with the town, the province and the coordinates.
Is the free postcode table from sqlblog.nl still current?
No. The file is from before 2010 and has 471,993 rows. For current addresses you need a file that is updated from the BAG every month.
How do I turn latitude and longitude into a geographic point in SQL Server?
With a computed column of the type geography: geography::STGeomFromText('POINT(lon lat)', 4326). The table in the script already does this in the column geographypoint.
Does the SQL script also work in MySQL?
No. The script is written for Microsoft SQL Server. MySQL has no geography type and gives a syntax error.

29 comments
Wat is je bron. Mogen we updates verwachten. Dit is verweg de meest bruikbare tabel die ik gevonden heb.
Ga hem zeker proberen.
Hi, ik heb deze ooit online gevonden maar die site werkt niet meer. Helaas geen updates dus maar beter dit als niets. Meeste bestanden zijn betaald. Op zich is die van postcode.store niet erg duur.
hi Ronald, je code geeft bij mij de nodige fouten - (punctuation error)
deze melding; bekend?
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS (geography::STGeomFromText(((('POINT('+CONVERT(VARCHAR(20),lon,(0)))+' ')+CON' at line 23
Deze SQL werkt alleen op microsoft SQL server.. :-)
ah.. dat verklaart een hoop. je hebt zeker geen mysql versie liggen;)?
JE kan hem wel gebruiken voor MySQL, alleen moet je dan die geo functies eruit halen
Excelbestand exporteren naar CSV, dan kan je het in Mysql importeren.
Plaatsnamen zijn vernacheld, kijk bijv. maar eens naar '1e Ex'.Half Friesland gebruikt ook stomme tekens in hun plaatsnamen en zijn ook allemaal incorrecte encoding weggeschreven. Gelukkig is het eenvoudig genoeg met een search & replace te repareren, want consistent.
Het is ook geen perfect script maar beter als niks :-)
@Rob: fijn dat je dit ook even deelt met je medemens...
;-)
In de meeste gevallen volstaat de postcode toch ;-) En met de lengte- en breedtegraad kan je alles berekenen:
http://stackoverflow.com/questions/4190154/given-coordinates-how-do-i-get-all-the-zip-codes-within-a-10-mile-radius
Ik zoek eigenlijk gewoon een mogelijkheid om een grote tabel met postcodes gekoppeld aan huisnummer (ranges) en plaatsnaam. In het formaat van:
postcode | huisnummer (range) | plaatsnaam
voorbeeld (fictief):
3200AB | 1 - 100 | Rotterdam
Deze tabel zou ik het liefst in Excel in kunnen lezen (dus CSV formaat of xlsx).
Is er iemand die mij kan vertellen hoe dit te doen?
Heel mooi, en super bedankt!
Bedankt! :)
Je bent geweldig! Hier heb ik wat aan! Eens kijken of dit ook fijn kan samenwerken met open street maps of google maps ;-)
Mooie tabel, maar ik krijg het script niet gedraaid in visual studio of SSMS, in beide gevallen krijg ik een melding over Memory en execute geeft ´query completed with errors´ zonder verder bericht.
Iemand tips hoe ik dit moet doen?
Beste allemaal.
Ik heb de excel gedownload
deze vervolgens als csv bestand opgeslagen
in foxpro met import de import wizard gebruikt en nu is het een postcode.dbf .
Top, vriendelijk bedankt! Precies wat ik zocht, ook met lengte- en breedtegraad.
Exporteren naar CSV is in de meeste gevallen de beste optie. Mysql en Postgres kunnen CSV's importeren.
Hup & hop :-)
Hi Ronald,
Ten eerste ongelooflijk bedankt voor deze dataset. Heel erg leuk en interessant.
Ik liep alleen tegen een klein foutje aan. Er zitten bepaalde Latitude Longitude coordinaten verkeerd in.
Voorbeeld: er zijn meerdere nederlandse plaatsen met een lat =< 49. Echter is het zuidelijkste puntje van Nederland boven de 50 lat. Is er een manier dit op te lossen? Of zal ik handmatig alles langs moeten gaan?
Alvast bedankt!
Renier
Dezelfde fout constateerde ik ook, nadat ik de excel eerst als csv in PostgreSQL had ingelezen en daarna in QGIS had gevisualiseerd. Ook liggen er een aantal postcodes in Vlaanderen en in het IJsselmeer.
Hi Ronald,
Hartstikke bedankt, hier bespaar je me een hoop tijd mee!
Handig artikel! Ik heb zelf ook die adressentabel gekocht en met je andere artikel heb ik de data nu ook in excel kunnen visualiseren.
Geweldig artikel! De Postcodetabel is echt nuttig voor veel toepassingen en het SQL-script maakt het nog makkelijker om mee te werken. Dank voor het delen!
Geweldig artikel! De uitleg over hoe de postcodetabel werkt en het bijgevoegde SQL-script zijn enorm nuttig. Ik kan niet wachten om te zien hoe ik dit kan toepassen in mijn eigen projecten. Bedankt voor het delen!
Geweldige blogpost! De uitleg over de postcode tabel en het bijbehorende SQL-script is zeer helder. Dit zal zeker helpen bij mijn volgende project. Bedankt voor het delen!
Geweldige post! De Postcodetabel is een waardevolle aanvulling voor mijn databaseprojecten. Dank voor de duidelijke uitleg en het handige SQL-script!
Geweldig artikel! De postcodetabel is echt nuttig voor mijn project. Bedankt voor het delen van het SQL-script, dat maakt het een stuk eenvoudiger om aan de slag te gaan. Kijk uit naar meer van dit soort handige inhoud!
Geweldig artikel! De postcodetabel is echt handig voor mijn projecten. Bedankt voor het delen van de SQL script, het zal mijn werk zeker vergemakkelijken!
Related blogs
Setup sp_send_dbmail attachment included!
Free E-Book SQL Server 2016
Linked Server - Why and how use them!