注册 登录
编程论坛 SQL Server论坛

求助函数语句

sijnplm 发布于 2007-07-05 15:17, 582 次点击

一个身份证号:52103198403153659
用什么语句把身份正号的出身年月提取出来 并且判断是否和当前的时间(年月日)匹配

4 回复
#2
laoliu5152007-07-05 17:12

declare @year int,@month int

declare @curyear int,@curmonth int

select @year=right(left('52103198403153659',9),4),@month=right(left('52103198403153659',11),2)

select @curyear=year(getdate()),@curmonth=month(getdate())

if @year=@curyear and @month=@curmonth

begin

.............

end

else

begin

........

end
没有测试不知道对不,取数就是这么取的。



#3
关小彤2007-07-06 14:52
也可以用subtring()函数

如130324198708145102
substring(idcard,9,6)这样就能选出870814了
#4
system322007-07-08 02:39
CREATE FUNCTION GetIDBirthDate (@id15 char(18))
RETURNS char(8) AS
BEGIN
DECLARE @Age as char(8)
Select @Age=case when len(@id15)=18 then SUBSTRING(@id15,7,8)
when SUBSTRING(@id15,7,2)>'50' then '19'+SUBSTRING(@id15,7,6)
else '18'+SUBSTRING(@id15,7,6) end
RETURN @Age
END
#5
system322007-07-08 02:40

15 18 的

1