我想在数据库中按照货号搜索记录。货号的结构是2大部分组成:
1。第一部分是字母,为2-3个英语字母,其表示货物的大类
2。第二部分是数字,为4-6位数字,其中该数字串的最后2位代表货物大类中的小类整个货号以文本字符串的格式保存在ACCESS中举例:货号CZ18901,CZ6301,大类都是CZ,小类都是01。只有中间数字189,和63不同。比如我想查询所有同一大类同一小类下的所有记录,我输入CZ**01,得到的是全部用CZ开头和01结尾的记录。请大家告诉我设计该SQL的思路,和实现的方法谢谢

解决方案 »

  1.   

    select * from tablename where left(货号,2)='CZ' and right(货号,2)='01'
      

  2.   

    select * from tname where 货号 like 'cz%01'
      

  3.   

    select * from tname where 货号 like 'cz%01'
      

  4.   

    各位兄弟,我试过上面你们的建议,结果查询的记录为0(其实应该是有合乎标准的记录的),我得语句如下
    Dim i As Integer
    For i = 1 To Len(strin)
        If Asc(Mid(strin, i, 1)) <= 57 Then
            Exit For
        End If
    NextstrPart1 = Left(strin, i - 1)strPart2 = Right(strin, 2)‘第一种写法
    str = "select * from candle where ItemNo like '" & strPart1 & "%" & strPart2 & "'"‘第二种写法
    str = "select * from candle where ItemNo like '" & strPart1 & "'and ItemNo like '" & strPart2 & "'"2种写法都没有查到记录,请帮我看看
      

  5.   

    Select * 
    From candle 
    Where left(ItemNo,i-1)='" & strPart1 & "'
    And right(ItemNo,2) = '" & strPart2 & "'"