sql search

hey guy i a table in sql where the client enter in the product detail, like name price and type.

now i have made one section where he enters in tags like welding, tourchs, gloves

now when he enters a new product he can select the tages or have no tages

now in my products table i have tags has my coloum name and this has text

mig torches,mig welding machines,welding

now i need to do a search to select the matching product to the tags.

please help
JCWEBHOSTAsked:
Who is Participating?
 
Ioannis ParaskevopoulosCommented:
Sorry, i found an error in the above example

DECLARE @SearchText VARCHAR(100)
SET @SearchText = 'welding'
select * from products 
where lower(tags) like '%,' + @SearchText --Ends with the search text
or lower(tags) like @SearchText + ',%'        --Starts with the search text
or lower(tags) like '%,' + @SearchText + ',%' --The search text is somewhere in the middle
or lower(tags) = @SearchText --Your search text is exactly the same with the tags column

Open in new window



Yet another fix. It should either start with your search text, or end with it or be in the middle or be alone.

Giannis
0
 
stergiumCommented:
Hello.
if i understood correctly you meant for something like this

select * from products where tags like '%welding%'
0
 
JCWEBHOSTAuthor Commented:
Yes, my text in tags goes like this

mig torches,mig welding machines,welding
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
JCWEBHOSTAuthor Commented:
so if the user enters

mig torches in any case it should search in products

but my problem is the comma

mig torches,mig welding machines,welding
0
 
Kamaraj SubramanianApplication Support AnalystCommented:
select * from products where lower(tags) like '%welding%'
0
 
JCWEBHOSTAuthor Commented:
what about the comma? ,
0
 
JCWEBHOSTAuthor Commented:
i want full word matches
0
 
Kamaraj SubramanianApplication Support AnalystCommented:
your column has the value as "mig torches,mig welding machines,welding"

if your user enters "welding", then what output you expect?
0
 
Ioannis ParaskevopoulosCommented:
Hi,

Try the following

DECLARE @SearchText VARCHAR(100)
SET @SearchText = 'welding'
select * from products 
where lower(tags) like '%,' + @SearchText + '%'
or lower(tags) like '%' + @SearchText + ',%'
or lower(tags) like '%,' + @SearchText + ',%'
or lower(tags) = ' + @SearchText + '

Open in new window


Giannis
0
 
Ioannis ParaskevopoulosCommented:
You need to make sure that all spaces between comas and your tags are trimed though. For instance if the client enters a product with a tag of ' welding ' you should make it 'welding' (stripping away the spaces before and after.
0
 
uaexpertCommented:
I suppose you need some query building UI component which help your users to design their own queries. There are plenty of them on the market, some are even free.
Try to google for "query builder component for asp.net" or something similar.
0
 
JCWEBHOSTAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.