数据库里面存储数据类似卡号                            购卡人
1275863001-1275863999           张三
8697445211-8697445523           李四.........上面示例的意思是,比如第一条数据 张三购买了 999张卡,号码从1275863001-1275863999       
现在知道一张卡号为1275863216 ,用这张卡号码搜索数据库,怎么才能得到所匹配的数据呢?
也就是说知道1275863216,怎样才能提出 购卡人是张三 的这条数据呢?

解决方案 »

  1.   

    ......where substring(cardrange,0,10)<'1275863216 ' and
    substring(cardrange,11,10)>'1275863216 '(当第一列的格式固定时可用)
      

  2.   

    抱歉,
    ......where substring(cardrange,0,10)<='1275863216 ' and
    substring(cardrange,11,10)>='1275863216 '
      

  3.   

    --如果卡号定长用以下这句
    select * from card
    where 1275863216 Between Convert(bigint,Left(卡号,10))
          AND Convert(bigint,substring(卡号,12,10))--如果卡号不定长用以下这句
    select * from card
    where 1275863216 between Convert(bigint,Left(卡号,(Charindex('-',卡号))-1))
          AND Convert(bigint,Right(rtrim(卡号),(Charindex('-',卡号))-1))
      

  4.   

    另外支持Mittermeyer(疾风之狼)的建议, 将起号和终号用两个字段来存储, 类型为bigint不要用char