October 8, 2005 at 8:35 am
I want a sql query that compare the data in a field. This field contain comma in between two word.
example: Skill Field
field value: Oracle,VB,ASP,PHP
field value: Java,VB,PHP,MYSql
field value: Java,VB,Oracle,Asp.net,MSSQL,Asp
want a query to find the a person have skill 'VB' and 'ASP
what 's query for the same
Vishal
October 8, 2005 at 9:09 am
A select * from myTable where (fieldValue like '%VB%Asp%') or (fieldValue like '%ASP%VB%') should get your results - just make sure it works even when the value starts or ends with either one of these skills or are right next to each other (think it does!!!)...
also, assuming that your db is case insensitive and it is not a consideration here...
(edited)...
**ASCII stupid question, get a stupid ANSI !!!**
October 9, 2005 at 4:01 am
This asks for a normalisation of the database. http://www.tutorialized.com/tutorial/Normalisation/7433
October 9, 2005 at 9:22 pm
Vishal,
If your field list looks like this...
field value: Oracle,VB,ASP,PHP
field value: Java,VB,PHP,MYSql
field value: Java,VB,Oracle,Asp.net,MSSQL,Asp
field value: Windows,HASP,Excel,VBA
Consider the following code to keep from listing the 4rh line when looking for ASP and VB...
SELECT *
FROM yourtable
WHERE ','+FieldValue+',' LIKE '%,ASP,%'
AND ','+FieldValue+',' LIKE '%,VB,%'
Of course, neither Sushilla's or my code examples for this problem will ever use the coveted CLUSTERED INDEX SEEK which is why Jo said this column really needs to be normalized.
If you don't have any 3rd party restrictions preventing the conversion of the column and you want to normalize it, post back... I'm sure Jo will be happy to help
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply