要写的查询语句:有一个表A  我获取name字段,条件: 1. typeid in (‘02’,’07’)2. contract_paymentratio =' 0.5' 
 3.  出生日期>=1975   通过身份证号:  IDCard,  取出生年份 主要是第三个不会,因为有的身份证号码是18位,有15位,还有其他,请教高手!

解决方案 »

  1.   

    其实判断也不复杂where
    case len(@s)when 15 then  '19'+substring(@s,7,2) when   18   then   substring(@s,7,4) end >=1975
      

  2.   

    where
    typeid in (‘02’,’07’)
    and
      contract_paymentratio =' 0.5'
    and  
      case len(IDCard) when 15 then  '19'+substring(IDCard,7,2) when   18   then   substring(IDCard,7,4) end >=1975
      

  3.   

    SELECT name from 表A
    where typeid in('02','07') and contract_paymentratio ='0.5' and substring(IDCard,7,4)>='1975'注意,标点符号要用半角的.
      

  4.   

    where
    case len(@s)when 15 then  '19'+substring(@s,7,2) when   18   then   substring(@s,7,4) end >=1975