{"id":6342,"date":"2023-07-10T06:34:00","date_gmt":"2023-07-10T04:34:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=6342"},"modified":"2026-05-18T13:55:46","modified_gmt":"2026-05-18T11:55:46","slug":"arithmetic-overflow-error","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/","title":{"rendered":"Arithmetic overflow error converting expression to data type int"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\" id=\"h-sql-server-tutorial-with-workaround-to-avoid-the-arithmetic-overflow-error-converting-expression-to-data-type-int-error\"><strong><em>SQL Server tutorial with workaround to avoid the &#8220;Arithmetic overflow error converting expression to data type int&#8221; error.<\/em><\/strong><\/h4>\n\n\n\n<p>With SQL Server, how to avoid this error : &#8220;Arithmetic overflow error converting expression to data type int&#8221;. Let&#8217;s insert some data into a table using a stored procedure for example. Facing this SQL Server error message can be disturbing. Even if SQL conversion errors are classical ones, finding the solution and apply the industry best practices to avoid them is very useful. <\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/#the-sql-server-arithmetic-overflow-conversion-error\" >The SQL Server Arithmetic overflow conversion error<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/#use-a-compatible-data-type-to-avoid-the-error\" >Use a compatible data type to avoid the error<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/#what-is-a-sql-server-arithmetic-overflow-error\" >What is a SQL Server arithmetic overflow error?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/#whats-the-biggest-number-for-a-sql-server-integer\" >What&#8217;s the biggest number for a SQL Server INTEGER?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/#whats-the-difference-between-int-and-bigint\" >What&#8217;s the difference between INT and BIGINT?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/#how-to-avoid-conversion-errors-with-sql-server\" >How to avoid conversion errors with SQL Server?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"the-sql-server-arithmetic-overflow-conversion-error\"><\/span>The SQL Server Arithmetic overflow conversion error<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In our use case, the stored procedure executing the query generates some dynamic T-SQL code. Then it executes the code and insert data from various tables into one single target table. It&#8217;s a <strong><em>typical SQL Server arithmetic overflow conversion error<\/em><\/strong>. While running the same piece of T-SQL code independently, that is outside the stored procedure, directly into the SQL Server Management Studio windows, no error is faced. But when integrating the same code into the stored procedure, this error is thrown:<\/p>\n\n\n\n<p><em>Msg 50000, Level 16, State 2, Procedure MyStoredProcedure, Line 123<br>Arithmetic overflow error converting expression to data type int.<\/em><\/p>\n\n\n\n<p>After analysis, the conversion error message didn&#8217;t come from the SELECT clause. The SQL INSERT clause from the same T-SQL stored procedure is throwing the error. The root cause is the the insertion of a big integer value into the table. For integer Data Type in SQL Server, the number must be between -2^31 (-2 to the power of 31) and 2^31 (2 to the power of 31).<\/p>\n\n\n\n<p><b>Namely the range for the INTEGER type is exactly&nbsp;between -2,147,483,648 and 2,147,483,648.<\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"use-a-compatible-data-type-to-avoid-the-error\"><\/span>Use a compatible data type to avoid the error<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The solution to avoid Arithmetic overflow error converting expression is to use a bigger <a href=\"https:\/\/sql602.sourceforge.net\/helpdir-en\/html\/HE_SQL2_DATOVETYPY.htm\" target=\"_blank\" rel=\"noopener\">data type<\/a>. The solution to avoid this arithmetic overflow error is to change the data type from INT to BIGINT or DECIMAL(11,0) for example. Please note that in this case the conversion error is because the integer number is too big. It can also be an insertion of a text value into an integer field. Check out the int, bigint, smallintand tinyint official SQL Server documentation.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"h-other-classical-conversion-questions\">Other classical conversion questions<\/h5>\n\n\n\n<p>This article shows how to simply avoid an Arithmetic overflow error converting expression to int in SQL Server. It happens when inserting a bigger number in an integer data type. Check out more classical SQL Server errors like the insert of a duplicate key.<\/p>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-6a0afe42e4c8b\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"what-is-a-sql-server-arithmetic-overflow-error\"><\/span>What is a SQL Server arithmetic overflow error?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>An arithmetic overflow error is an error faced when converting from one SQL Server data type to another one. For example from a numeric figure to an integer because the integer type can handle smaller figures compared to the numeric type.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-6a0afe42e4c8c\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"whats-the-biggest-number-for-a-sql-server-integer\"><\/span>What&#8217;s the biggest number for a SQL Server INTEGER?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The biggest number for the SQL Server integer data type is from -2 to the power of 31 till 2 to the power of 31. It means from -2^31 to 2^31 which is exactly this range: from -2,147,483,648 to 2,147,483,648. To avoid conversion error, always consider the maximum value for the data and size the database and the data types accordingly.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-6a0afe42e4c8d\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"whats-the-difference-between-int-and-bigint\"><\/span>What&#8217;s the difference between INT and BIGINT?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A bigint is an integer, i.e. a number without decimals, and in SQL Server it can go from -2^63 that is exactly -9,223,372,036,854,775,808 to 2^63-1 which is 9,223,372,036,854,775,807 and is using 8 Bytes in storage. While an INTEGER is from -2^31 which equals -2,147,483,648 to 2^31-1 which is exactly 2,147,483,647. An INTEGER data is stored on 4 Bytes.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-6a0afe42e4c8e\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><span class=\"ez-toc-section\" id=\"how-to-avoid-conversion-errors-with-sql-server\"><\/span>How to avoid conversion errors with SQL Server?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>One good practice to avoid conversion errors during is to put in place controls for the inputs. And moreover make sure to control the values inserted in the database. For example, users can only enter valid dates in a date field.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n<p><strong>Check out how to <a href=\"https:\/\/expert-only.com\/en\/t-sql\/calculate-difference-between-two-dates\/\">manage time difference in hours minutes and also seconds with T-SQL<\/a>.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/expert-only.com\/en\/t-sql\/calculate-difference-between-two-dates\/\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>SQL Server tutorial with workaround to avoid the &#8220;Arithmetic overflow error converting expression to data type int&#8221; error. With SQL Server, how to avoid this error : &#8220;Arithmetic overflow error converting expression to data type int&#8221;. Let&#8217;s insert some <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/errors\/arithmetic-overflow-error\/\" title=\"Arithmetic overflow error converting expression to data type int\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":6337,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[486],"tags":[],"class_list":{"0":"post-6342","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-errors"},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/6342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=6342"}],"version-history":[{"count":4,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/6342\/revisions"}],"predecessor-version":[{"id":31225,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/6342\/revisions\/31225"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/6337"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=6342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=6342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=6342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}