Reputation: 81
I am trying to execute the following Query
select distinct pincode as Pincode,CAST(Date_val as DATE) as Date,
SUM(cast(megh_38 as int)) as 'Postage Realized in Cash',
SUM(cast(megh_39 as int)) as 'MO Commission',
from dbo.arrow_dtp_upg
group by pincode,Date_Val
but I am getting an error "Conversion failed when converting the nvarchar value '82.25' to data type int."
Am I using a wrong data type?
Upvotes: 0
Views: 883
Reputation: 43021
The string "82.25" represents a float (or a decimal) not an int, so use cast(megh_38 as float)
if you need a float.
If you require the integer part only then use floor(cast(megh_38 as float))
.
Upvotes: 1
Reputation: 26
One possible problem is delimiter (dot vs comma). Questions - why you prefer nvarchar for store float or int values? Maybe decimal or float is better solution?
Upvotes: 0
Reputation: 636
You could try this:
cast(megh_38 as decimal(10,2))
cast(megh_39 as decimal(10,2))
Upvotes: 0