贴得到处都是,加个年龄字段 select * from table where 年龄>=35 and 年龄<=45
(1)如果加个年龄字段,则简单 select * from table where 年龄 between 35 and 45 (2)如果不能加年龄字段,而只有上面的几个字段,就复杂了。KingOfDali说的对,身份证号有15位和18位的,这样很难进行判断。要是身份证号能固定的话,就好了。你可以取出当前日期,再从身份证号中取出出生日期的那段数字,两者相减,结果就是年龄了,最后用(1)方法进行判断。
select * from tablename where age between 30 and 40但想了一下,应该不是这样 你的目的一定是要从身份证上面取出DATA,这个DATA表示年龄 然后在搜索35至45 是不是呀? 但是不知道身份证上面哪一位表示年龄, 能和我说一下吗?/
试试吧: select * from (select year(getDATE( ))-SUBSTRING(sid, start1,length1 ) as age,[name],id from table where length(sid)=15) where age between 30 and 45 union all select * from (select year(getDATE( ))-SUBSTRING(sid, start2,length2 ) as age,[name],id from table where length(sid)=18) where age between 30 and 45
1根据身份证号 like '%年份%' 过滤出绝大部分数据,可能有巧合的 2再跟据PATINDEX(身份证号,年份)=7等出现的位置来判断,就保险了
试试select * from tablename where 年龄 between 25 and 50
记不太清楚,大概这样可以。Select ID, Name, SID, SUBSTRING(sid, 7, 8) as Age From Table Where SUBSTRING(sid, 7, 8) < '19670101' and SUBSTRING(sid, 7, 8) > '1957' and Len(sid) = 18UnionSelect ID, Name, SID, SUBSTRING(sid, 7, 6) as Age From Table Where SUBSTRING(sid, 7, 6) < '670101' and SUBSTRING(sid, 7, 6) > '570101' and Len(sid) = 15另外:设年龄字段并不太好,还不如设Birthday?!嘿嘿。
select * from table where 年龄>=35 and 年龄<=45
select * from table where 年龄 between 35 and 45
(2)如果不能加年龄字段,而只有上面的几个字段,就复杂了。KingOfDali说的对,身份证号有15位和18位的,这样很难进行判断。要是身份证号能固定的话,就好了。你可以取出当前日期,再从身份证号中取出出生日期的那段数字,两者相减,结果就是年龄了,最后用(1)方法进行判断。
你的目的一定是要从身份证上面取出DATA,这个DATA表示年龄
然后在搜索35至45
是不是呀?
但是不知道身份证上面哪一位表示年龄,
能和我说一下吗?/
select * from (select year(getDATE( ))-SUBSTRING(sid, start1,length1 ) as age,[name],id from table where length(sid)=15) where age between 30 and 45
union all
select * from (select year(getDATE( ))-SUBSTRING(sid, start2,length2 ) as age,[name],id from table where length(sid)=18) where age between 30 and 45
2再跟据PATINDEX(身份证号,年份)=7等出现的位置来判断,就保险了
Where SUBSTRING(sid, 7, 8) < '19670101' and SUBSTRING(sid, 7, 8) > '1957' and Len(sid) = 18UnionSelect ID, Name, SID, SUBSTRING(sid, 7, 6) as Age From Table
Where SUBSTRING(sid, 7, 6) < '670101' and SUBSTRING(sid, 7, 6) > '570101' and Len(sid) = 15另外:设年龄字段并不太好,还不如设Birthday?!嘿嘿。