Showing posts with label sosiaaliturvatunnus. Show all posts
Showing posts with label sosiaaliturvatunnus. Show all posts

20210305

How to get person's birthdate from Finnish social security number with SQL-query

 Finnish social security number is datemask ddmmYYxAAbc

  • dd = date with two numbers.
  • mm = month with two numbers.
  • YY = year with two numbers.
  • x = "delimeter" character. It can be '+','-' or 'A'. It presents century.

    • '+' = 1800
    • '-' = 1900
    • 'A' = 2000
  • AAbc = varying numbers and caharacters for id purposes including cheksum. We are not interested in about it this time.

SQL-query:


DECLARE @sSecurityId char(11);

SET @sSecurityId = N'221177-123Z';  

select CONVERT(date, CASE SUBSTRING(@sSecurityId, 7, 1)
    WHEN '-' THEN '19'
    WHEN 'A' THEN '20'
    WHEN '+' THEN '18' 
END + SUBSTRING(@sSecurityId, 5, 2) + SUBSTRING(@sSecurityId, 3, 2) + SUBSTRING(@sSecurityId, 1, 2)) as birthdate

Result: 1977-22-11


Keywords for Finnish developers:

Kuinka muuttaa suomalainen sosiaaliturvatunnus, eli sotu, päivämääräksi tai päiväksi SQL-haun avulla.


When scheduled BAT-files cascades

Server was acting slowly. What have happened? When I opened Task Manager. There were thousands of cmd-programs open. I noticed there were so...