Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Error converting data type nvarchar to numeric

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-08 : 05:11:27
Anyone can help me ?

When i run this query after to prompt error message in below "
Error converting data type nvarchar to numeric.

trx_dat.unit_price is nvarchar(20)
trx_dat.qty numeric field.

------------------------------ SQL query
CAST(CONVERT(numeric(36, 2), dbo.trx_dat.unit_price * dbo.trx_dat.item_qty AS numeric(36, 2)) AS total_commission

How to edit this query can be get the total commission ?



gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-08 : 07:05:48
that's not valid syntax. Post the entire query.
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-08 : 08:47:45
CAST(CONVERT(numeric(36, 2), dbo.trx_dat.unit_price AS numeric(36, 2)) * dbo.trx_dat.item_qty AS total_commission

Regards
Viggneshwar A
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-08 : 08:58:35
that's not a query; that's an expression. And, the expression has invalid syntax!

e.g. If I try to use your expression in a query:


select CAST(CONVERT(numeric(36, 2), dbo.trx_dat.unit_price AS numeric(36, 2)) * dbo.trx_dat.item_qty AS total_commission
from dbo.trx_dat


Intellisense correctly underlines the first keyword "AS" in red, since the syntax is invalid.

Because the syntax is invalid, I cannot run a query using your expression. That means that I cannot get the error "Error converting data type nvarchar to numeric." Since you are getting this error, your query must be different somehow.

Please post the whole query, starting with a SELECT and ending with a semi-colon.
Go to Top of Page
   

- Advertisement -