Solved

sql search

Posted on 2013-02-04
12
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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