Situatie
Mai jos este o functie ce returneaza data de nastere primind ca si parametru un CNP.
Solutie
create function [dbo].[BirthdateFromCNP]
(
@cnp varchar(13)
)
RETURNS datetime
AS
BEGIN
DECLARE @prefixAn varchar(2)
SET @prefixAn =
CASE
WHEN substring(@cnp,1,1) in (‘5’, ‘6’, ‘9’)
THEN ’20’
WHEN substring(@cnp,1,1) in (‘3’, ‘4’)
THEN ’18’
ELSE ’19’
END
RETURN
cast((@prefixAn+substring(@cnp,2,2)+’-‘+substring(@cnp,4,2)+’-‘+substring(@cnp,6,2)) as datetime)
END