Page 1 of 1
Can you check if a field has NO numeric values in the query?
Posted: Wed May 23, 2012 5:16 am
by simonmlewis
I have a field that contains things like this: "433|211|309|", but sometimes it will be "||||", as occasionally when removing the numbers, it leaves some ||| behind.
This isn't great, but is there a way in the SELECT *... query where I can say "where field only contains numeric"??
Re: Can you check if a field has NO numeric values in the qu
Posted: Wed May 23, 2012 5:36 am
by simonmlewis
Heavens I'm making this difficult - just "where field > 0".
If it's 311|233|.... it comes up with one entry. If it's "|||", it comes up empty.
Re: Can you check if a field has NO numeric values in the qu
Posted: Tue Jan 20, 2015 5:51 am
by desheikh
as occasionally when removing the numbers, it leaves some ?
Re: Can you check if a field has NO numeric values in the qu
Posted: Tue Jan 20, 2015 2:56 pm
by requinix
Sounds like you should fix your database so you aren't storing multiple values in one column.
But to answer the question, MySQL has
REGEXP so you can search for anything not matching "[0-9]".
Re: Can you check if a field has NO numeric values in the qu
Posted: Tue Jan 20, 2015 7:44 pm
by twinedev
While you have a "fix" to make it work, it is good to eliminate the issue before it reaches the database.
Whenever you write the value to the database, do trim( $variable, '|' ) so you get rid of any possible leading/tailing pipes, and if it is only pipes, you will get empty string.