web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

Arithmetic overflow error converting numeric to data type numeric in computed column in d365

(0) ShareShare
ReportReport
Posted on by 290

Recently, I've created a view which is union of the customer and vendor transaction. I've added a computed column to calculated remain AmountMST. Everything works fine until I faced "Arithmetic overflow error converting numeric to data type numeric" error on other server. As I investigated on the data I discovered that there are some transaction for the vendor which has large amount for example: 10596974868300600.

I check the view in sql and see that the computed column is cast to numeric(32,16). This is the view in sql server

SELECT        T1.CUSTACCOUNT AS CUSTACCOUNT, T1.VENDACCOUNT AS VENDACCOUNT, T1.VOUCHER AS VOUCHER, T1.TRANSTYPE AS TRANSTYPE, T1.TRANSDATE AS TRANSDATE, 
                         T1.CURRENCYCODE AS CURRENCYCODE, T1.POSTINGPROFILE AS POSTINGPROFILE, T1.DOCUMENTDATE AS DOCUMENTDATE, T1.DUEDATE AS DUEDATE, T1.INVOICE AS INVOICE, T1.TXT AS TXT, 
                         T1.AMOUNTMST AS AMOUNTMST, T1.EXCHADJUSTMENT AS EXCHADJUSTMENT, T1.SETTLEAMOUNTMST AS SETTLEAMOUNTMST, T1.LASTSETTLEDATE AS LASTSETTLEDATE, 
                         T1.LASTSETTLEVOUCHER AS LASTSETTLEVOUCHER, T1.CLOSED AS CLOSED, T1.PARTYRECID AS PARTYRECID, T1.MAINACCOUNTID AS MAINACCOUNTID, T1.MAINACCOUNTNAME AS MAINACCOUNTNAME, 
                         T1.POSTINGPROFILENAME AS POSTINGPROFILENAME, T1.DATAAREAID AS DATAAREAID, T1.PARTITION AS PARTITION, 1010 AS RECID, (CAST(('CustTrans') AS NVARCHAR(10))) AS TABLENAME, 
                         (CAST((((T1.AMOUNTMST)   (T1.EXCHADJUSTMENT)) - (T1.SETTLEAMOUNTMST)) AS NUMERIC(32, 16))) AS REMAINAMOUNT, (CAST((CASE WHEN T1.CLOSED = N' ' THEN 1 ELSE 2 END) AS INT)) 
                         AS TRANSSTATUS, (CAST((0) AS INT)) AS ACCOUNTTYPE
FROM            CUSTWITHRELATEDVEND T1
UNION
SELECT        T1.CUSTACCOUNT AS CUSTACCOUNT, T1.VENDACCOUNT AS VENDACCOUNT, T1.VOUCHER AS VOUCHER, T1.TRANSTYPE AS TRANSTYPE, T1.TRANSDATE AS TRANSDATE, 
                         T1.CURRENCYCODE AS CURRENCYCODE, T1.POSTINGPROFILE AS POSTINGPROFILE, T1.DOCUMENTDATE AS DOCUMENTDATE, T1.DUEDATE AS DUEDATE, T1.INVOICE AS INVOICE, T1.TXT AS TXT, 
                         T1.AMOUNTMST AS AMOUNTMST, T1.EXCHADJUSTMENT AS EXCHADJUSTMENT, T1.SETTLEAMOUNTMST AS SETTLEAMOUNTMST, T1.LASTSETTLEDATE AS LASTSETTLEDATE, 
                         T1.LASTSETTLEVOUCHER AS LASTSETTLEVOUCHER, T1.CLOSED AS CLOSED, T1.PARTYRECID AS PARTYRECID, T1.MAINACCOUNTID AS MAINACCOUNTID, T1.MAINACCOUNTNAME AS MAINACCOUNTNAME, 
                         T1.POSTINGPROFILENAME AS POSTINGPROFILENAME, T1.DATAAREAID AS DATAAREAID, T1.PARTITION AS PARTITION, 1010 AS RECID, (CAST(('VendTrans') AS NVARCHAR(10))) AS TABLENAME, 
                         (CAST((((T1.AMOUNTMST)   (T1.EXCHADJUSTMENT)) - (T1.SETTLEAMOUNTMST)) AS NUMERIC(32, 16))) AS REMAINAMOUNT, (CAST((CASE WHEN T1.CLOSED = N' ' THEN 1 ELSE 2 END) AS INT)) 
                         AS TRANSSTATUS, (CAST((1) AS INT)) AS ACCOUNTTYPE
FROM            VENDWITHRELATEDCUST T1

when I change numeric(32,16) to (32,6) and run select query on the view no error comes. but when the data type is numeric(32,16) it failed. Also using 33 instead of 32  will be fix the issue.

But The problem is even I cast the calculation to numeric(32,6) (using sysComputed::Cast) at the end casting to (32,16) is added automatically. it seems every real computed column is stored as numeric(32,16).

This is my computed method:

 public static server str remainAmountMST(int _branchNum)
	{
        #define.CompView(CustVendView)
        #define.CompCustDS(CustWithRelatedVend)
        #define.CompVendDS(VendWithRelatedCust)
        #define.AmountMstCol(AmountMST)
        #define.ExchAdjustCol(ExchAdjustment)
        #define.SettlementCol(SettleAmountMST)
		
		if(_branchNum)
        {
            return  SysComputedColumn::subtract(
                SysComputedColumn::add(
                                        SysComputedColumn::returnField(
                                            tableStr(#CompView),
                                            identifierStr(#CompCustDS),
                                            fieldStr(#CompCustDS, #AmountMstCol)),
                                        SysComputedColumn::returnField(
                                            tableStr(#CompView),
                                            identifierStr(#CompCustDS),
                                            fieldStr(#CompCustDS, #ExchAdjustCol))
                                      ),
               SysComputedColumn::returnField(
               tableStr(#CompView),
               identifierStr(#CompCustDS),
               fieldStr(#CompCustDS, #SettlementCol))

         );
        }
		else
        {
            return  SysComputedColumn::subtract(
				SysComputedColumn::add(
										SysComputedColumn::returnField(
											tableStr(#CompView),
											identifierStr(#CompVendDS),
											fieldStr(#CompCustDS, #AmountMstCol)),
										SysComputedColumn::returnField(
											tableStr(#CompView),
											identifierStr(#CompVendDS),
											fieldStr(#CompCustDS, #ExchAdjustCol))
									  ),
               SysComputedColumn::returnField(
               tableStr(#CompView),
               identifierStr(#CompVendDS),
               fieldStr(#CompCustDS, #SettlementCol))

         );
        }

So How can I cast the computed column to numeric(32,6) ?

I have the same question (0)
  • Blue Wang Profile Picture
    on at

    HI Nastaran Hakimi,

    community.dynamics.com/.../did-you-know-how-many-decimals-has-real-type-in-d365fo-by-default-1626303103

    The problem is that in the database numeric(32,16) data type is used to store fields. Numeric(32,16) data type stores numbers with no more than 32 digits total and no more than 16 digits after the decimal point.

    For example, your number 10596974868300600 has a length of 17+16=33, so when you use numeric(32,16) there will be problems, as you said, you can use 33 instead.

    You can try to customize EDT and change NoOfDecimals to what you need.

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    Real data type always has 16 scale but when you create a new EDT in D 365 F&O, default Scale is 6. 

    to get the casting to (32,6). Just set the EDT on the commuted column like below: I used OOB RealBase EDT, you can create new EDT as well if you want to change the scale.

    pastedimage1596751898760v1.png 

    results:

    pastedimage1596752013570v2.png

  • vinitgoyal2005 Profile Picture
    6,332 on at

    Hi Nastaran,

    Were you able to resolve the issue?

  • Nastaran Profile Picture
    290 on at

    Dear Vinit

    Today I tested your solution but no it is not working. Again numeric (32,16) is the data type in sql server. All EDT s I have tested have scale 6 but sql server shows numeric(32,16).

  • Nastaran Profile Picture
    290 on at

    Dear Blue

    I have tested your suggestion as well, it seems EDT is not changing the format in database, and it is just used to display value. I set NoOfdecimals 34 and then check SQL server my view SQL code again numeric(32,16) is the datatype.

  • Blue Wang Profile Picture
    on at

    HI Nastaran Hakimi,

    Is the field a real type?

    60.PNG

  • Nastaran Profile Picture
    290 on at

    Dear Blue,

    yes my computed column datatype is real .when I see my view in sql server shows numeric(32,16) as the type for the remainAmount column. Is TestField computed column? and if so please add my logic to the method. I want to be sure that casting to 32,16 is not related to the computed column or the logic which has been used. ( for example maybe adding two real column causes this behaviour.

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    I just created the same view with RealBase as EDT assigned(as mentioned before). look at the SQL view generated below:

    pastedimage1597078652078v1.png

    Recheck the SQL view generated. Run the View command on new SQL and delete column and then test if there is any other error?

    PS. I hope after the change you have done the DB sync successfully. 

  • vinitgoyal2005 Profile Picture
    6,332 on at

    Hi Nastaran,

    Were you able to resolve the issue? Please let us know.

  • Nastaran Profile Picture
    290 on at

    Dear Vinit

    No I couldn't solve the issue this is the picture of the column type in Microsoft SQL server.

    Capture222.PNG

    One thing I should mention which I thought it wasn't important is that the view is not union of the exactly custTrans and vendTrans. It is union of two view. The first view contains cusTrans and custTable as data source, the second view includes vendTrans and custtable and vendTable as a datasource. The field which I needed in both view is same so I achived to union these two view.

    This is view 1

    view1.PNG

    This is view 2

    View2.PNG

    Do you think this causes the issue? I will try the view unioning just custTrans and vendTrans.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Siv Sagar Profile Picture

Siv Sagar 283 Super User 2025 Season 2

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 196 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 139 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans