views:

250

answers:

2

Hi, I am trying to filter my results in the query builder of Visual Studio 2008 so that when it executes the query to SELECT data from the field i chose, it will only retrieve last names that start with an user input. I figure this is to be done using the filter tab. SO i put a filter I used different filters but did not work with me. I'm using mySQL database.

here is the code I used:

SELECT Last_Name FROM contact_info WHERE (Last_Name LIKE 'prefixText%') will return null ........ SELECT Last_Name FROM contact_info WHERE (Last_Name LIKE @prefixText%) will give me error ............ SELECT Last_Name FROM contact_info WHERE (Last_Name LIKE '@prefixText%')will return null ................ SELECT Last_Name FROM contact_info WHERE (Last_Name LIKE @prefixText)will return null ............................

here is the error I'm getting: [URL=http://img180.imageshack.us/i/errorm.jpg/][IMG]http://img180.imageshack.us/img180/8983/errorm.jpg[/IMG][/URL] please advice what is the correct syntax for mySQL to use in query builder of Visual Studio 2008 to return fields start with first letter that the user enter???

+1  A: 

If @prefixText is a parameter then try..

SELECT Last_Name FROM contact_info WHERE Last_Name LIKE '%'+@prefixText+'%';

LIKE Operator

kevchadders
I tried your way but I'm getting an error >>>here is the error:[URL=http://img341.imageshack.us/i/error2a.jpg/][IMG]http://img341.imageshack.us/img341/2333/error2a.jpg[/IMG][/URL]
Eyla
+1  A: 

this code work OK for me.

SELECT First_Name FROM contact_info WHERE (First_Name LIKE CONCAT(@prefixText, '%'))

Eyla