Select * from table where fld in ('關鍵字1','關鍵字2'...)

解决方案 »

  1.   

    select c.name from sysobjects t,syscolumns c where t.id=c.id and t.name=表名用以上语句得出这个表的所有字段,然后用游标和动态SQL处理
      

  2.   

    strname=Split(你的数组, ",")
     //////intCount = UBound(strname)(找出数组的长度)///////  For intCount = 0 To UBound(strname) -1
       if intCount =0 then
    strFold = fld like '% &"strname(intCount)"& %'
    else
    strFold = strFold &  " or fld like '% &"strname(intCount)"& %' "
    end if
      Next intCountSelect * from table where & " strFold
      

  3.   

    StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT * FROM 表名 WHERE (字段1 LIKE '%'"+@WordList[0].ToString()+"'%'");
    for (int i = WordList.Count; --i > 0;)
    {
    strSql.Append(" OR 字段1 LIKE '%'"+@WordList[i].ToString()+"'%'");
    } strSql.Append(") AND (字段2 LIKE '%'"+@WordList[0].ToString()+"'%'");
    for (int i = WordList.Count; --i > 0;)
    {
    strSql.Append(" OR 字段2 LIKE '%'"+@WordList[i].ToString()+"'%'");
    }生成的语句是"SELECT * FROM 表名 WHERE (字段1 LIKE '%'关键字1'%' OR 字段1 LIKE '%'关键字2'%') AND (字段2 LIKE '%'关键字1'%' OR 字段2 LIKE '%'关键字2'%') ORDER BY ID DESC"这样的语句能执行吗? 感觉有问题
      

  4.   

    多了一个单引号 生成的SQL满足要求了是不是效率比较低啊有没有更好的SQL"SELECT * FROM 表名 WHERE (字段1 LIKE '%关键字1%' OR 字段1 LIKE '%关键字2%') AND (字段2 LIKE '%关键字1%' OR 字段2 LIKE '%关键字2%') ORDER BY ID DESC"