Extract age from CNP
Posted: 2023-07-22 05:43
Please I need some support to Translate
CREATE FUNCTION [dbo].[BDGetDataNasteriiFromCNP]
(
@CNP nvarchar(255)
)
RETURNS datetime
AS
BEGIN
DECLARE @returnVal datetime
DECLARE @Sex int
DECLARE @An varchar(10)
DECLARE @Luna varchar(10)
DECLARE @Zi varchar(10)
select @Sex = substring(@CNP, 1, 1),
@An = substring(@CNP, 2, 2),
@Luna = substring(@CNP, 4, 2),
@Zi = substring(@CNP, 6, 2)
if @Sex in (1,2,7)
begin
set @An = ’19’+ @An
end
else
begin
set @An = ’20’+@An
end
select @returnVal = convert(datetime, @An+@Luna+@Zi, 112)
RETURN @returnVal
END[/color][/color]
Default query begins like:
SELECT `Program_Operator`.`CNP` FROM `Program_Operator`
WHERE `Program_Operator`.`ID`='%ID%'
CREATE FUNCTION [dbo].[BDGetDataNasteriiFromCNP]
(
@CNP nvarchar(255)
)
RETURNS datetime
AS
BEGIN
DECLARE @returnVal datetime
DECLARE @Sex int
DECLARE @An varchar(10)
DECLARE @Luna varchar(10)
DECLARE @Zi varchar(10)
select @Sex = substring(@CNP, 1, 1),
@An = substring(@CNP, 2, 2),
@Luna = substring(@CNP, 4, 2),
@Zi = substring(@CNP, 6, 2)
if @Sex in (1,2,7)
begin
set @An = ’19’+ @An
end
else
begin
set @An = ’20’+@An
end
select @returnVal = convert(datetime, @An+@Luna+@Zi, 112)
RETURN @returnVal
END[/color][/color]
Default query begins like:
SELECT `Program_Operator`.`CNP` FROM `Program_Operator`
WHERE `Program_Operator`.`ID`='%ID%'