Extract age from CNP

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
fanton
Posts: 3
Joined: 2022-01-20 16:37

Extract age from CNP

Post by fanton » 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%'

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1231
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Extract age from CNP

Post by onoehring » 2023-08-01 08:24

Hi,

please use the "code" tag to show code - make it easier to read.

What do you need help with?
Is this a MSSQL Server Statement (of MySQL)?
What is your problem?
What is your goal (what are you trying to accomplish)? Do you want to read some date?

Your question is unclear (too unclear to me at least to give another answer).

Olaf

Post Reply