Building SQL string

S

Steve

Could somebody please give me a basic run-through and
example of how to build an SQL string and display said
string in MSG Box.
I am building a QBF form and need some help with the SQL
string. I using Access 2002 DAO.
Thanks for reading and hopefully responding to this plea.
 
D

Douglas J. Steele

Not quite sure what you're looking for. A SQL string is just a statement
that you can assign to a variable, something like:

Dim strSQL As String

strSQL = "SELECT Table1.Field1, "
strSQL = strSQL & "Table2.Field2 "
strSQL = strSQL & "FROM Table1 "
strSQL = strSQL & "INNER JOIN Table2 "
strSQL = strSQL & "ON Table1.Field1 = Table2.Field1 "
strSQL = strSQL & "WHERE Table1.Field1 < 5 "
strSQL = strSQL & "ORDER BY Table2.Field2"

MsgBox "The SQL I'm going to use is " & strSQL

The assignment could also have been done using:

strSQL = "SELECT Table1.Field1, " & _
"Table2.Field2 " & _
"FROM Table1 " & _
"INNER JOIN Table2 " & _
"ON Table1.Field1 = Table2.Field1 " & _
"WHERE Table1.Field1 < 5 " & _
"ORDER BY Table2.Field2"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top