Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

conversion failed when converting the varchar value to datatype int

$
0
0

Hi All,

I am summing columns(numeric) together and sometimes there is a negative number so the total row is causing an error.

select
		d.DIVName1
		,c.CCYName1
		,'Foreign Currency Payables'
		,SUM(CASE WHEN p.ACPFSMID IN (128) THEN p.ACPBalanceBase ELSE 0 END) AS [January 13]
		,SUM(CASE WHEN p.ACPFSMID IN (129) THEN p.ACPBalanceBase ELSE 0 END) AS [Feburary 13]
		,SUM(CASE WHEN p.ACPFSMID IN (130) THEN p.ACPBalanceBase ELSE 0 END) AS [March 13]
		,SUM(CASE WHEN p.ACPFSMID IN (128, 129, 130) THEN '$' + REPLACE(CONVERT(varchar,(CAST(p.ACPBalanceBase AS money)),1),'.00','') ELSE 0 END) AS [Total]

		

from AccountsPayable p
inner join Division d
on p.ACPDIVID = d.DIVID
inner join Currency c
on p.ACPTransactionCCYID = c.CCYID

group by 
		d.DIVName1
		,c.CCYName1
order by 
		d.DIVName1
		,c.CCYName1

This is getting error message:

Conversion failed when converting the varchar value '-2262.2800' to data type int.

Thanks for any help.



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>