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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Searching comma separated value

Author  Topic 

tomat
Starting Member

3 Posts

Posted - 2005-11-23 : 05:12:22
hi,
I have a column (varchar) with numeric comma separated value in it (a number value, ex: 1,2,3 etc)
what is the best way to do searching on this column?

I found that full text search with CONTAINS seems not working,

Tommy

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-23 : 05:37:46
>>I have a column (varchar) with numeric comma separated value in it (a number value, ex: 1,2,3 etc)

Why do you have that format?
Make your table properly normalised so that it is easy for data manipulations

What does this query return?
Select Columns from yourTable where varchar_column like 'someNumber'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-23 : 05:42:13
you can use like for that matter...

Select <Column_Names> From <TableName> Where Column_Name like '%Number%'...???


Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

tomat
Starting Member

3 Posts

Posted - 2005-11-24 : 06:38:26
thanks for the feedback,

Some background on this problem:

My varchar column is not design to be searchable in the beginning; the data comes from HTML multiple selections, ex: 1,4,7,9 etc. so I just save it right away to DB without normalizing it and I have an ASP function to deal with it.

Later there is a need to search on this column for some reason, so I thought I could use full-text search function but I end-up with all being noise words,

Currently I'm using LIKE '%<number>%' to deal with that problem, while I'm normalizing the data.

Thanks for the feedback and comments


Tommy
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-24 : 07:42:15
Did that method work correctly?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tomat
Starting Member

3 Posts

Posted - 2005-11-25 : 05:42:39
It’s not perfect, but enough for simple search.
If you search for 1 it will match: 1,15,51 or any number with 1, etc.

tommy
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2005-11-25 : 05:51:22
U can try this
Select <Column_Names> From <TableName> Where replace(Column_Name,','+Column_Name+',') like '%,'+Number+',%'
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-25 : 06:43:18
Then you need to split the data and compare
Refer this split function
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-11-25 : 08:46:12
"Select <Column_Names> From <TableName> Where replace(Column_Name,','+Column_Name+',') like '%,'+Number+',%'"

I don't think you meant to use REPLACE did you?

Select <Column_Names>
From <TableName>
Where ','+Column_Name+',' like '%,1,%' -- assuming you are looking for "1"

Kristen
Go to Top of Page
   

- Advertisement -