We read your photo as:

How to fix the MySQL error "Out of range value for column 'BonusMonth'" when adding a column?

Computer Science

ScanSolve AI Answer

The error ERROR 1264 (22003): Out of range value for column 'BonusMonth' occurs because you are trying to assign the entire HireDate (which is a date value) directly to an INT column named BonusMonth. MySQL cannot implicitly convert a full date like 'YYYY-MM-DD' into a simple integer within the range of an INT data type.

You need to use the MONTH() function to extract only the month number from the HireDate column, which will then be an integer (1-12) and fit correctly into the BonusMonth column.

Here is the corrected query:

ALTER TABLE Employee ADD COLUMN BonusMonth INT AS (MONTH(HireDate)) STORED;
  • MONTH(HireDate): This function extracts the month number (an integer from 1 to 12) from the HireDate column. This integer value is then correctly stored in the BonusMonth column.
Was this helpful?

Still stuck on this one?

Ask a follow-up, and the answer starts from this question.

Got a different question?Ask your own question