Solved

Error converting data type nvarchar to numeric - sql server

Posted on 2013-11-12
4
6,853 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: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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

830 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