SQLTeam.com | Weblogs | Forums

Error converting data type varchar to numeric

#1

Hi Guys,

have a case statement that giving me error how can I replace '0' with blank or '-' ?
error:
Error converting data type varchar to numeric.

Columns:
Quarter =varchar
amount= decimal
below just showing the totalQ1 only (case statement)

Thanks!

select co,empid,quarter,

,(case when QUARTER = 1 then sum(amount) over ( partition by empid, quarter) else '-' end) as totalQ1
from deduction

image

0 Likes

#2

,(case when QUARTER = 1 then CAST(sum(amount) over ( partition by empid, quarter) as varchar(20)) else '-' end) as totalQ1

0 Likes

#3

Thanks Lewie, just had the same solution! mine dies not have the "as varchar(20)" but I will add it.
Pasi.

0 Likes