Solved

Error converting data type nvarchar to numeric - sql server

Posted on 2013-11-12
4
6,648 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 125 total points
ID: 39642726
you cannot convert '$' symbol to decimal, change " [Sales Order $ to date]" column to Varchar(30)
0
 
LVL 48

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:ScottPletcher
ScottPletcher 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now