Reputation: 3310
I'm trying to compile a query in my dataset which accepts one variable and searches three columns of my SQL Server 08 database table. The query is below but it doesn't ask for the variable. I believe the system perceives the @Query as text since it's enclosed in the single quotes. Any ideas?
SELECT * FROM Customer WHERE
((NAME LIKE '%@Query%') OR (Surname LIKE '%@Query%') OR (Telephone LIKE '%@Query%'))
I am using the visual dataset editor. The way I'm calling it from the VB.NET code is:
Dim dtCustomers As DataTable
dtCustomers = Me.CustomerTableAdapter.GetSearchCustomers("myString")
Upvotes: 1
Views: 679
Reputation: 27377
The LIKE condition has to contain the content of @Query, not the string '@query'
SELECT * FROM Customer WHERE
((NAME LIKE '%'+@Query+'%') OR (Surname LIKE '%*+@Query+'%') OR (Telephone LIKE '%'+@Query+'%'))
Upvotes: 1