Statement the SQL statements we've talked about so far are relatively simple, and if you can go through a standard recordset loop query, these statements can also meet some more complex requirements. But why do we have to stick to the basic standards of taste? You can add additional symbols, such as and, or, and not to accomplish more powerful functions.
Take the following SQL statement 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 for your current knowledge of SQL, the above examples are not difficult to explain, but the above statement does not make it very clear to see how the conditional words are glued to a single SQL statement.
Multi-line statement
When the SQL statement is not understood, you might as well break the whole statement into multiple lines of code, and then incrementally add the parts of the query statement to the same variable based on the existing variables:
SQL = "Select C_firstname, C_lastname, c_emailaddress, C_phone"
sql = SQL & "from customers"
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 Customers
WHERE c_firstname like ' a% ' and c_emailaddress NO NULL order by C_lastname,
C_firstname "
The whole sentence according to the decomposition after the obvious good read much! When you are debugging, you may be more willing to knock a few more characters to change the program to read better. Keep in mind, however, that you need to add more space before closing the quotes or after opening the quotes so that you don't get a few words together when the strings are connected.