Solved

sql search

Posted on 2013-02-04
12
278 Views
Last Modified: 2013-02-07
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
0
Comment
Question by:JCWEBHOST
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 13

Expert Comment

by:stergium
ID: 38850209
Hello.
if i understood correctly you meant for something like this

select * from products where tags like '%welding%'
0
 

Author Comment

by:JCWEBHOST
ID: 38850216
Yes, my text in tags goes like this

mig torches,mig welding machines,welding
0
 

Author Comment

by:JCWEBHOST
ID: 38850218
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 38850247
select * from products where lower(tags) like '%welding%'
0
 

Author Comment

by:JCWEBHOST
ID: 38850254
what about the comma? ,
0
 

Author Comment

by:JCWEBHOST
ID: 38850260
i want full word matches
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 38850266
your column has the value as "mig torches,mig welding machines,welding"

if your user enters "welding", then what output you expect?
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 38850272
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
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 38850280
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
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
ID: 38850327
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
 
LVL 2

Expert Comment

by:uaexpert
ID: 38858482
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
 

Author Closing Comment

by:JCWEBHOST
ID: 38866971
thanks
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question