Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql search in c#

Author  Topic 

shamsherule
Starting Member

4 Posts

Posted - 2011-12-17 : 01:11:18
Hi there,

I am trying to write an SQL command in c# that will search for multiple entries in a column .

Basically, a user will enter several key words into a text box, and the SQL command needs to return the rows where all of those words are found in a column.

So we have a field in the table called 'Vdetails' in which files
like

ID VCode Kms Compny MYr
111069 1GAHG39KX91179765 132000 05-CHVRLET 2009
111256 2MEHM75V79X624234 34000 02-MERCURY 2009
111293 4T1BK36B59U343918 53000 09-TOYOTA 2009
111340 JTHBJ46G092298017 69000 09-TOYOTA 2009
111291 4T1BK36B18U290407 86000 09-TOYOTA 2008
stored and I need to find row
111293 4T1BK36B59U343918 53000 09-TOYOTA 2009
111340 JTHBJ46G092298017 69000 09-TOYOTA 2009

when a user enters "TOYOTA 2009" into the search form.

I have tried using the LIKE command, but this only works when one keyword is entered.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-17 : 01:39:56
for multiple keyword search, you need to use a parsing udf to parse the values based on what delimiter you use(ie comma seperated, pipe seperated etc) and get the individual values and then use it in LIKE

see an example udf below

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -