Page 1 of 1

Extract age from CNP

Posted: 2023-07-22 05:43
by fanton
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%'

Re: Extract age from CNP

Posted: 2023-08-01 08:24
by onoehring
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