Arithmetic overflow error converting nvarchar to data type numeric

Last Post 11 Sep 2009 09:58 AM by JASBRYDEN. 1 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
JASBRYDEN
New Member
New Member

--
11 Sep 2009 07:50 AM
Hi

I am setting is SQL script to create a table to send to all the manages the sales.

I have one line that seems to be giving me a lot of problems, which is the 'Total Sales' line.

If I remove this line the query runs perfect no problems.

However when I have that one line in I am getting the following error.


Msg 8115, Level 16, State 6, Line 3
Arithmetic overflow error converting nvarchar to data type numeric.





DECLARE @tableHTML NVARCHAR(MAX) ;

SET @tableHTML =
N'<H1>Beltek Sales</H1>' +
N'<tr><th>Date: </th>'+ (SELECT CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY]) +
N'<tr><th> Total Sales: </th>'+ (select sum (CAST(invoicetotal as decimal(10,4)))from beltekSales) +
N'<table border="1">' +
N'<tr><th>Sales Rep Name</th><th>Customer Number</th><th>Bill To</th><th>Bill Name</th><th>Cash Amount</th><th>Total Tax</th><th>Invoice Tax</th>' +
CAST ( (select td=Salesrepname, '',
td=Customerno, '',
td=Billto, '',
td=BillName, '',
td=CashAmount, '',
td=Tax1total, '',
td=InvoiceTotal
from beltekSales
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;


The table looks like this

CREATE TABLE [dbo].[BeltekSales](
[WarehouseNo] [varchar](6) NULL,
[Salesrepname] [varchar](30) NULL,
[Customerno] [varchar](8) NULL,
[Billto] [varchar](30) NULL,
[BillName] [varchar](30) NULL,
[CashAmount] [money] NULL,
[Tax1total] [money] NULL,
[InvoiceTotal] [money] NULL
) ON [PRIMARY]

Any ideas as to what I should do ???
JASBRYDEN
New Member
New Member

--
11 Sep 2009 09:58 AM
I do not understand



Acceptable Use Policy
---