Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:08:29+00:00 2026-06-02T02:08:29+00:00

How can I check if a provided value is a number/ integer or letters?

  • 0

How can I check if a provided value is a number/ integer or letters?

For instance, this is my working SQL,

SELECT 
    p.*

FROM page AS p

WHERE p.title = 'home'

AND IF(CONVERT('7', SIGNED INTEGER) IS NOT NULL, p.parent_id != p.page_id, p.parent_id = p.page_id)

‘7‘ is variable, sometime it is a number, sometimes it is ‘self‘.

So when it is a number, then p.parent_id != p.page_id

Else p.parent_id = p.page_id

But I can get it right as my SQL query returns always p.parent_id != p.page_id.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:08:30+00:00Added an answer on June 2, 2026 at 2:08 am

    You can use a REGEXP.

    AND CASE
        WHEN ('7' REGEXP '^[0-9]+$') THEN
          p.parent_id != p.page_id
        ELSE p.parent_id = p.page_id
    END
    

    The reason your CONVERT() fails to work as expected is that a non-numeric string will always be cast as 0, rather than NULL.

    mysql> SELECT CONVERT('7a', SIGNED INTEGER);
    +-------------------------------+
    | CONVERT('7a', SIGNED INTEGER) |
    +-------------------------------+
    |                             7 |
    +-------------------------------+
    
    mysql> SELECT CONVERT('self', SIGNED INTEGER);
    +---------------------------------+
    | CONVERT('self', SIGNED INTEGER) |
    +---------------------------------+
    |                               0 | <-- non-numeric strings always cast to 0
    +---------------------------------+
    

    Your method may work if you compare against 0 instead of NULL, but I don’t have a good way to test. However, this fails if the value actually is 0, wherein you’ll get the wrong comparison back.

    AND IF(CONVERT('7', SIGNED INTEGER) <> 0, p.parent_id != p.page_id, p.parent_id = p.page_id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PLEASE CHECK ANSWERS by VolkerK too, he provided another solution, but I can't mark
I can check for iPhone with this code: (navigator.userAgent.match(/iPhone/i)) But I want to target
With this code I can check the caret position in a textarea in firefox:
The question is this: Create a page with a number of links. Then write
I have a page where a user can either select a vendor via dropdown
In our application we have number of AggregatorTypes (idea copied from SQL Server) i.e.
Can someone offer some help on this? I'm getting an 'invalid key value type'
Can check out here alt text http://51hired.com/static/problem.bmp
I know that I can check whether the linux timestamp in $time is today
I'm aware that I can check an ActiveRecord through the rails console but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.