Http://user.qzone.qq.com/382164370! APP = 2 & via = qz. hashrefresh & Pos = 1346996967
The code is in VC ++:
Cstring SQL, STR; SQL. format (_ T ("select * From tbpatient where admitdatebetween cdate ('% S % s') and cdate (' % S % s')"), dtstartdate. format (_ T ("% x"), dtstarttime. format (_ T ("% x"), dtenddate. format (_ T ("% x"), dtendtime. format (_ T ("% x"); // fuzzy query of fields in MySQL Concat (email, address) like 'like % DF %' If (! Strkeyword. isempty () {// isnull (expression, replace) in SQL Server has the replacement function, // access needs to be combined with isnull (expression), IIF (condition, value_if_true, value_if_false) function // 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 );
A rewrite code
Cstring SQL, STR; SQL. Format (_ T ("select * From tbpatient"); If (! M_bdisplayall) // if not all are displayed, the search condition {Str. format (_ T ("where admitdatebetween 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; // fuzzy query of the combined fields MySQL Concat (email, address) like 'like % DF %' If (! Strkeyword. isempty () {// isnull (expression, replace) in SQL Server has the replacement function, // access needs to be combined with isnull (expression), IIF (condition, value_if_true, value_if_false) function // 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, add sorting trace1 ("% s \ n", SQL );