Searching with parameters and wildcards

jamie123

Well-known member
Joined
May 30, 2008
Messages
82
Programming Experience
Beginner
I'm programming in vb.net, using vs2005 and sqlserver2005.

I have a pretty simple question, I'm trying to conduct a search on all columns of a given table, the search is driven by a parameter, but I want the search to return rows with "Red dog" if I search for "Red", so I need the wildcard to work, and I don't know how to formulate it. I read online to do the following, but it does not work:

VB.NET:
Expand Collapse Copy
SELECT ID, Frame, [Stock Num], Type, [Insurance Code], Mfgr, Color, Size, Cost, Retail, [% Markup], [Qty on Hand], [Reorder Point], [Ordered From], [Qty on Order], [Qty to Order], [Date Ordered], [Date Recieved], [Order Initials], [Recieve Initials], [Date Sold], BarCode FROM dbo.Materials WHERE Frame like '%'+@search+'%' OR [Stock Num] like '%'+@search+'%' OR Type like '%'+@search+'%' or [Insurance Code] like '%'+@search+'%'

As you can see, I didn't finish out the query on all columns because it wasn't working so far, what am i doing wrong here regarding wildcards? and can I query an sql table and search all columns the way I am doing so now? or does it need to be written differently?

Thank you!
 
Figured out how to do it: '%'+@param+'%'

However, I am trying to search across multiple columns in a given table. My search will find information from all of the columns, but none combined. For example, I have two columns: name, color. If i search bob, it'll filter out all but bob. If i search brown, it'll filter out all but brown. However, if i search bob brown, nothing will come up, I need this to show columns where bob is the name or color, and brown s the name or color. I know its in the structure of my sql statement, but how can i formulate this to do what i want? If anymore information is needed please ask, thanks in advance!
 
Back
Top