请教高手: 
我想对输入文本框中的字符进行模糊查询 
该怎样写sql语句 
 txtSQL = txtSQL & " temp1.Locate_code='" & Trim(Text(0).Text) & "'" 
其中txtsql有初值到 where结束 
该怎样修改上面的sql语句呢 
不胜感激! 
 
我用的是access数据库

解决方案 »

  1.   

    如果temp1表中的Locate_code字段是字符型,这句就是对的。
    如果是数值型就改成txtSQL = txtSQL & " temp1.Locate_code=" & Trim(Text(0).Text)
      

  2.   

    如果是sqlserver数据库,应该是这样
    txtSQL = txtSQL & " temp1.Locate_code='%" & Trim(Text(0).Text) & "%'"
      

  3.   

    我上面打错了,应是
    txtSQL = txtSQL & " temp1.Locate_code LIKE '%" & Trim(Text(0).Text) & "%'"
      

  4.   

    txtSQL = txtSQL & " where temp1.Locate_code LIKE '%" & Trim(Text(0).Text) & "%'"
    或者:
    txtSQL = txtSQL & " and temp1.Locate_code LIKE '%" & Trim(Text(0).Text) & "%'"
      

  5.   

    我的txtSQL初值为:
    txtSQL = "SELECT temp1.* from (SELECT Arc_volume.*, T1CodeDept.NameDept as name, T1CodeDept.AddressDept as address, T1CodeDept.TypeDept as type FROM T1CodeDept INNER JOIN Arc_volume ON T1CodeDept.CodeDept = Arc_volume.Dept_Code) as temp1 where"
    在一个条件下想执行模糊查询
    txtSQL = txtSQL & " where temp1.Locate_code LIKE '%" & Trim(Text(0).Text) & "%'"
    最后
     Set rs = db.OpenRecordset(txtSQL) ,但是总是查不出来,查询语句应该没有问题吧
    好望高手指点,不胜感激!保证给分!!!
      

  6.   

    Like如果使用在Where里,其实就和 '=' 一样.没什么效果.
    在Filter里使用 Like试试.