Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

varchar to 'array' for 'where in'

Status
Not open for further replies.

wimkumpen

Programmer
Jun 13, 2009
8
BE
Hello,

I have a varchar field where the values look like: "5,3,9"

I want to use those values in a 'where in':

select * from tabel where id in (varcharfield)

is something like this possible?
 
it is possible, but horribly clumsy and inefficient

WHERE CONCAT(',',varcharfield,',') LIKE CONCAT('%,',id,',%')

your problem is the comma-delimited string of values stored in a single column, which violates first normal form

any chance you could redesign that?

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
I think I would use the FIND_IN_SET function in such a case.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
I think both solutions can be used. But the FIND_IN_SET is a little bit cleaner to use. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top