代码是在VC++里面:
[cpp] view plaincopyprint?
CString sql, str;
sql.Format(_T("SELECT * FROM tbPatient 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")));
//字段合并的模糊查询 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;
}
TRACE1("%s\n", sql);
一样可以用concat进行连接字符串,再使用like查询。