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
 General SQL Server Forums
 New to SQL Server Programming
 converting error

Author  Topic 

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-08 : 05:33:08
Anyone can help !???

Error: Conversion failed when converting the nvarchar value '12.5'
to data type int.

how to edit below of sql query , make it work ?

cast(case when dbo.item.anly_code25 is null or dbo.item.anly_code25='' then 0 else dbo.item.anly_code25*dbo_item_qty end as numeric(36)) as total_commission

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2015-01-08 : 07:14:25
the casting should be done while multiplication

case when dbo.item.anly_code25 is null or dbo.item.anly_code25='' then 0 else cast(dbo.item.anly_code25 as numeric(36))*dbo_item_qty end as total_commission

--
Chandu
Go to Top of Page

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-08 : 20:58:30
Anyone can help ?
I try below this query is still not work and same error message.

case when dbo.item.anly_code25 is null or dbo.item.anly_code25='' then 0 else cast(dbo.item.anly_code25 as numeric(36))*dbo.item_qty end as total_commission
Go to Top of Page

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-08 : 21:16:15
this anly_code25 nvarchar (25)field have different data include in below.

data sample
100
1.2
space
0
0
2.4

This query have problem , it is decmial point to make the error ?

case when dbo.item.anly_code25 is null or dbo.item.anly_code25='' then 0 else cast(dbo.item.anly_code25 as numeric(36))*dbo_item_qty end as total_commission

how to change this query can handle convert decimal ?


Go to Top of Page

usafelix
Posting Yak Master

165 Posts

Posted - 2015-01-09 : 00:12:30
Hi anyone, I am try use this query to fixed the nvarchar convert to
numeric problem and solve it , so happy.

case when dbo.bk_item.atp_item='POINTS' THEN cast(dbo.item.anly_code25 as numeric))*1 ELSE cast(dbo.item.anly_code25 as numeric)*dbo.trx_dat.item_qty END AS Total_Commission


Go to Top of Page
   

- Advertisement -