Solved

Error converting data type nvarchar to numeric - sql server

Posted on 2013-11-12
4
7,128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 125 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 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 125 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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

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 ?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

617 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