当前位置:Gxlcms > 数据库问题 > sql 查询年龄

sql 查询年龄

时间:2021-07-01 10:21:17 帮助过:30人阅读

ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: wgx -- Create date: <Create Date, ,> -- Description: <Description, ,> -- ============================================= CREATE FUNCTION [dbo].Func_GetAge ( @birthday bigint ) RETURNS int AS BEGIN DECLARE @age int ; if(@birthday is null or LEN(@birthday)<8) begin set @age=0; end else begin set @age=FLOOR(datediff(DY, (LEFT(@birthday, 4) + - + SUBSTRING(CAST(@birthday AS varchar), 5, 2) + - + SUBSTRING(CAST(@birthday AS varchar), 7, 2) + 00:00:00), getdate()) / 365.25); end RETURN @age; END GO

dbo.Func_GetAge(19820212)

技术分享图片

sql 查询年龄

标签:@age   substr   int   class   com   arch   技术分享   ediff   day   

人气教程排行