Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error converting data type nvarchar to numeric - sql server

Posted on 2013-11-12
4
Medium Priority
?
7,434 Views
Last Modified: 2013-11-14
Please guide me how to resolve below error in below update statement.

Error: Error converting data type nvarchar to numeric.

update  dbo.#temp set [Sales Order $ to date]='$' + ' ' + cast(cast((SELECT TOP 1 SUM([SO Net Value]) FROM bcamdb.dbo.SAP_ZVBAK BAKSales with(nolock)
inner join  dbo.#temp on BAKSales.[Customer PO] LIKE LTRIM(CAST(dbo.#temp.[CPO Number] as varchar(50)))+'%') AS DECIMAL (18,2)) AS nvarchar(50))

Please find the attached #temp table structure.
temp-table
0
Comment
Question by:sqldba2013
4 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 39642726
you cannot convert '$' symbol to decimal, change " [Sales Order $ to date]" column to Varchar(30)
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39643727
OR remove the concatenation with '$' as you are building the temp table, but at output add the dollar symbol.

If you are doing calculations on those columns you would want to keep those fields as decimals I think.

Whichever logic you adopt, you will want to apply it consistently to the money fields:

          , [Sales Order $ to date] decimal(18, 2)
...
          , [Invoice $ to date] decimal(18, 2)
...
          , [Invoice $ Delta] decimal(18, 2)
0
 
LVL 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 500 total points
ID: 39646175
Or use money/smallmoney data type, which will accept (but ignore) the '$', and will have 4 decimal places.
0
 

Author Closing Comment

by:sqldba2013
ID: 39650413
--
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question