| The SQL statements we have mentioned so far are relatively simple. If we can use standard recordset for loop query, these statements can also meet more complex requirements. However, why do we have to stick to the basic level of simplicity? You can add other symbols, such as and, or, and not, to complete more powerful functions. The following SQL statement is used as an example:
SQL = "select c_firstname, c_lastname, c_email from customers where c_email is
Not null and c_purchase = '1' or c_purchase = '2' and c_lastname like
'A % '" As far as your current knowledge of SQL is concerned, the above examples are not difficult to explain, but the above statements do not clearly show you how condition statements are glued into a single SQL statement. Multi-line statements
When SQL statements are hard to understand, you may want to break down the entire statement into multiple rows.CodeThen, the component of the query statement is gradually added based on the existing variable and stored in the same variable:
SQL = "select c_firstname, c_lastname, c_emailaddress, c_phone"
SQL = SQL & "from MERs"
SQL = SQL & "where c_firstname like 'a % 'and c_emailaddress not null"
SQL = SQL & "order by c_lastname, c_firstname"
In the last sentence, the SQL variable contains the following complete SELECT statement:
"Select c_firstname, c_lastname, c_emailaddress, c_phone from MERs
Where c_firstname like 'a % 'and c_emailaddress no null order by c_lastname,
C_firstname" The entire sentence is obviously much read after being decomposed! During debugging, you may be more comfortable typing a few more charactersProgramBetter read. However, you must remember that you need to add spaces before or after the quotation marks are closed to ensure that the strings are not joined together. |