SQL Syntax

  • Thread starter Thread starter M Massie
  • Start date Start date
M

M Massie

I'm trying to use this in a VB module. I want to use the
string stored in "Campaign" as query criteria

"SELECT Imports.* FROM Imports WHERE (Imports.[Campaign
Code])="' %Campaign% '", Connection

I get a syntax error.
 
"SELECT Imports.* FROM Imports
WHERE (Imports.[Campaign Code])= '%" & Campaign & "%'"

(at the end, they are single-quote + double-quote.)

This assumes [Campaign Code] is a Text Field.
 
I'm trying to use this in a VB module. I want to use the
string stored in "Campaign" as query criteria

"SELECT Imports.* FROM Imports WHERE (Imports.[Campaign
Code])="' %Campaign% '", Connection

I get a syntax error.

Three errors actually. You have unmatched " marks, for one; the =
operator does not recognize wildcards; and Access (I presume you're
using Access, not SQL/Server) uses * as a wildcard rather than %.

If you're using an ADO recordset use

"SELECT Imports.* FROM Imports WHERE (Imports.[Campaign Code] LIKE '
%Campaign% '"

For DAO (an Access .mdb file) use * in place of %.
 
i am John from Greece!
Try this:

"SELECT Imports.* FROM Imports WHERE (((Imports.[Campaign
Code])='" & ... & "'"

where ... is the value of a variable
if variable type is not a String, don't use the char ' before and afyer "
 
Back
Top