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 7886993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:27:52+00:00 2026-06-03T05:27:52+00:00

I have an alias in the select like this: SELECT CASE …. WHEN 1

  • 0

I have an alias in the select like this:

SELECT
    CASE ....
    WHEN 1 THEN somefield * -10
    WHEN 0 THEN somefield * 10
    END as myAlias
FROM
    ....

the problem is that at the first record that mysql seeks, it marks the “myAlias” as UNSIGNED
but in some next record the same alias produces a SIGNED integer, then I have the error:

BIGINT UNSIGNED value is out of range in....

so, how to tell mysql before it does any operation that “myAlias” is a SIGNED INTEGER?

thanks!

edit:

I’ve tried

SELECT
    CAST(CASE ....
    WHEN 1 THEN somefield * -10
    WHEN 0 THEN somefield * 10
    END AS SIGNED) as myAlias
FROM
    ....

without success!

  • 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-03T05:27:53+00:00Added an answer on June 3, 2026 at 5:27 am

    I assume that the field in your table is declared as UNSIGNED INTEGER. In that case, you have to type cast the field in the THEN clause of the CASE expression. Below example illustrates a sample.

    Create and insert script:

    CREATE TABLE mytable
    (
         numberfield INTEGER UNSIGNED
       , bitfield BIT
    );
    
    INSERT INTO mytable (numberfield, bitfield) VALUES
      (134, 1),
      (673, 0),
      (855, 1),
      (133, 0),
      (778, 1),
      (234, 0);
    

    Type casting the field in THEN clause: SQL Fiddle Demo

    SELECT
        CASE bitfield
            WHEN 1 THEN CAST(numberfield AS SIGNED) * -10
            WHEN 0 THEN CAST(numberfield AS SIGNED) * 10
        END as myAlias
    FROM mytable
    

    Output:

    MYALIAS
    -------
    -1340
    6730
    -8550
    1330
    -7780
    2340
    

    Alternative way to write the above query: SQL Fiddle Demo

    SELECT
        CAST(numberfield AS SIGNED) * 
        (
            CASE bitfield
                WHEN 1 THEN -10
                WHEN 0 THEN 10
            END
        ) as myAlias
    FROM mytable
    

    Output:

    MYALIAS
    -------
    -1340
    6730
    -8550
    1330
    -7780
    2340
    

    Without type casting the field: SQL Fiddle Demo

    SELECT
        CASE bitfield
          WHEN 1 THEN numberfield * -10
          WHEN 0 THEN numberfield * 10
        END as myAlias
    FROM mytable
    

    Error:

    Data truncation: BIGINT UNSIGNED value is out of range in ‘(db_5b3bb.mytable.numberfield * -(10))’: SELECT CASE bitfield WHEN 1 THEN numberfield * -10 WHEN 0 THEN numberfield * 10 END as myAlias FROM mytable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a Select Statement like this: SELECT T1.TEXT, T2.FIELD FROM TABLE1 T1,
I have a query like this: select data.* from ((select table1.col1 as a) union
i have a question how to use an alias from a select query: $timecheck
So, I've got a query that looks something like this: SELECT id, DATE_FORMAT(CONVERT_TZ(callTime,'+0:00','-7:00'),'%b %d
How can I do something like this in nHibernate: select count(*) from (subquery) It
I have a query like this: SELECT Name, REPLACE(RTRIM(( SELECT CAST(Score AS VARCHAR(MAX)) +
I have a table called Subscriptions. I'd like to redirect any LINQ select from
I have an entity that is mapped with a <join> element like this: <class
If have a control that acts like a record selector from a database, say,
I have three tables that I use which has proved this problem to be

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.