By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,499 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Need Help with SQL Statement Please

P: 62
Hello

I am writing an address book application.

I want to be able to search for Surnames starting with a particular character let's say "A". The character is getting passed in a String to my business class. I am using Access 2007.

I have: SELECT * FROM Address WHERE Surname LIKE '" + str + "'

But I am getting an Error : Missing Syntax. I know th eabove is incorrect as I only want to retrun record starting with the Character passed.

E.G A return all Surnames starting with A , B return all Surnames starting with B etc.

Any help or recommendations would be greatly appreciated.

Thanks,

Lan
Nov 30 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 635
Hello

I am writing an address book application.

I want to be able to search for Surnames starting with a particular character let's say "A". The character is getting passed in a String to my business class. I am using Access 2007.

I have: SELECT * FROM Address WHERE Surname LIKE '" + str + "'

But I am getting an Error : Missing Syntax. I know th eabove is incorrect as I only want to retrun record starting with the Character passed.

E.G A return all Surnames starting with A , B return all Surnames starting with B etc.

Any help or recommendations would be greatly appreciated.

Thanks,

Lan
Hi

Assuming this is in VBA then something like this

SQL = "SELECT * FROM Address WHERE Surname LIKE '" & str & "*'"

?

MTB
Nov 30 '07 #2

P: 62
Hi

Thanks for Input.

I'm using C#, Seems right from what I've read, but It return nothing.

Any other clues?

Thanks again,
Nov 30 '07 #3

P: 62
Hey Mike,
Just got it.:

sql = "SELECT Surname, Name, Telephone FROM Address WHERE Surname LIKE '" + str + "%'";

Thanks a mil. Your input was they key.

Happy coding,
Nov 30 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.