• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

SQL select troubles... bad db design?

demon42

Member
The more I think about it, the more I think my design is bad and that I should re-work the db... but I'd rather not if I can avoid it.

My database is storing a list of classes, like what a university would have. CRN, title, days of the week, etc. I am implementing the db through a Java application, many methods would have to be re-writtenif I needed to re-structure the db (poor planning on my part, I guess).

I decided to store days of the week as an integer, +64 for mon, +32 for tue, +16 for wed, etc. but now I have a problem searching! I can take a search string "w" and change it into a 16, no problem. The question is how do I match that against the number 84 ("mwf")?

My SELECT (much simplified) is like this:
sqlQuery = String.format("SELECT * FROM CLASS WHERE Day LIKE '%%%s%%'", filters[0]);

It's really much more complicated than that, but it should be enough to get my meaning.

I'm really struggling with this, hoping not to re-work the db. Any ideas?
 
There are bitmas operators in sql that you could use. I don't remember the exact syntax, but I'm pretty sure every sql reference would have it.
 
Got it!
sqlQuery=String.format("SELECT * FROM CLASS WHERE DAY & '%s' = '%s'", filters[0], filters[0])

where filters are a string representation of the value in question, aka for wednesday, "16"

Thanks again for putting me on the right track!
 
Back
Top