求一个判断身份号性别SQL语句?

郭富成都小吃 2008-11-21 12:44:16
求一个判断身份号性别SQL语句?
最好是18位和15位的一起判断?
...全文
124 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sy_binbin 2008-11-21
  • 打赏
  • 举报
回复
declare @card varchar(20)
set @card = '你的身份证'
IF len(@card)=15
begin
select sex=case convert(int,right(rtrim(@card),1))%2
when 0 then '女'
else '男' end
end
else if len(@card)=18
select sex=case convert(int,substring(@card,17,1))%2
when 0 then '女'
else '男' end
sy_binbin 2008-11-21
  • 打赏
  • 举报
回复
晕,你到底想干什么呢??

在SQL里写多麻烦啊

郭富成都小吃 2008-11-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sy_binbin 的回复:]
15位的
select sex=case convert(int,right(rtrim(210103800825002),1))%2
when 0 then '女'
else '男' end

18位的
select sex=case convert(int,substring(身份证号,17,1))%2
when 0 then '女'
else '男' end
[/Quote]

可以写在一个语句里面吗?
sy_binbin 2008-11-21
  • 打赏
  • 举报
回复
15位的
select sex=case convert(int,right(rtrim(210103800825002),1))%2
when 0 then '女'
else '男' end

18位的
select sex=case convert(int,substring(身份证号,17,1))%2
when 0 then '女'
else '男' end
郭富成都小吃 2008-11-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sy_binbin 的回复:]
<%
a = "身份证号码"
if len(a) = 15 then
lastNO = right(a,left(len(a)-1,1))
elseif len(a) = 18 then
lastNO = left(right(a,2),1)
end if
if lastNO mod 2 = 0 then
response.Write "女"
else
response.Write "男"
end if
%>
[/Quote]

大哥我要的是SQL语句?
sy_binbin 2008-11-21
  • 打赏
  • 举报
回复
<%
a = "身份证号码"
if len(a) = 15 then
lastNO = right(a,left(len(a)-1,1))
elseif len(a) = 18 then
lastNO = left(right(a,2),1)
end if
if lastNO mod 2 = 0 then
response.Write "女"
else
response.Write "男"
end if
%>

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧