SQL多字段模糊查询
生活随笔
收集整理的這篇文章主要介紹了
SQL多字段模糊查询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
http://user.qzone.qq.com/382164370#!app=2&via=QZ.HashRefresh&pos=1346996967
代碼是在VC++里面:
一種改寫的代碼
CString sql, str;sql.Format(_T("SELECT * FROM tbPatient"));if (!m_bDisplayAll) //非全部顯示則添加搜索條件{str.Format(_T(" WHERE admitDate BETWEEN CDate('%s %s') AND CDate('%s %s')"),dtStartDate.Format(_T("%x")), dtStartTime.Format(_T("%X")),dtEndDate.Format(_T("%x")), dtEndTime.Format(_T("%X")));sql += str;//字段合并的模糊查詢 MYSQL concat(email, address) like 'like%df%'if(!strKeyWord.IsEmpty()){//SQL Server中IsNull(expression, replace)有替換功能, //Access需要結合IsNull ( expression ), iif (condition, value_if_true, value_if_false )函數//str.Format(_T(" AND IsNull(name, ' ') + IsNull(Empid, ' ') LIKE '%%%s%%'"), // strKeyWord.GetBuffer(0));str.Format(_T(" AND iif(IsNull(name),' ',name) & iif(IsNull(Empid),' ',Empid) LIKE '%%%s%%'"), strKeyWord.GetBuffer(0));sql += str;}}//sql += _T(" ORDER BY ASC"); //DESC, 添加排序TRACE1("%s\n", sql);
總結
以上是生活随笔為你收集整理的SQL多字段模糊查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大众、长安“缝合怪”?换代天籁消费者不买
- 下一篇: 一个C++加密工具EncryptDecr