Click to See Complete Forum and Search --> : Problem with SQL sentence for MS Access


evth_sux
October 19th, 2007, 03:49 PM
Hi everyone,

I'm trying to execute a SQL command in VC++.


CString sSentence;
sSentence = "SELECT * FROM Client WHERE Name LIKE 'j*'";
rs.Open (CRecordset::forwardOnly, sSentence.c_str ());

So it must return the names in the Client table starting with 'j', but this function doesn't return a register. This sentence works fine in MS Access and it returns the names starting with 'j' correctly.

If I use


sSentence = "SELECT * FROM Client WHERE Name LIKE 'the_complete_name'";
rs.Open (CRecordset::forwardOnly, sSentence.c_str ());

it returns the registers involving that name.

I've read and searched this and other forums, but the solutions I found doesn't work.

Thanks in advance for the help.

hspc
October 19th, 2007, 05:30 PM
Try:
"SELECT * FROM Client WHERE Name LIKE 'j%'"
I know that MS Access uses * instead of %... But I remember that this was how it works when using OLEDB... Anyway, you won't lose a lot if you try...

evth_sux
October 19th, 2007, 06:15 PM
Hmmm,

sSentence = "SELECT * FROM CientWHERE NameLIKE '";
sSentence += "j";
sSentence += "%';";

This works... I would like to know why.

Thanks averyone.

davide++
October 22nd, 2007, 07:38 AM
Hi all.

I've met with this problem yet...

The '%' character is the standard SQL wildcard that takes the place of any substring in queries, but Access accepts '*' also.
In my opinion, when you perform the query within Access '*' is correct, but when the query is executed via ODBC (as probably yo're doing) then only the SQL standard wildcard '%' is right.