I have a problem where I need to search for a value in a ODBC which is a reserved word.
So:
SELECT * FROM Customer WHERE AccountNumber = 'Sum'
In this case, 'Sum' is a reserved word and so I get a syntax error.
In access the error is "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect"
Is there a way I can search for such a string?
Parameterise the string you wish to use as part of the WHERE clause and as I had the same problem when using the keyword 'PRIORITY'. After modifying the C# code to use parameters, it worked.
using (OdbcCommand command = conn.CreateCommand())
{
command.CommandText = "SELECT account_ref FROM SALES_LEDGER WHERE account_ref = '?'";
command.Parameters.Add(new OdbcParameter("?", accountCode));
using (OdbcDataReader reader = command.ExecuteReader())
{
...
}
}
Instead of searching for 'Sum' specifically. You could try:
SELECT * FROM Customer WHERE AccountNumber LIKE('%Sum%')