I have a query if vatgroup chooses x6
or x7
in output has to show '-'
other than than it has to show the value what is come.
Based on below query my output comes as *
for other than x6 or x7.
case when t1.VatGroup in('X6','X7') then '-' Else CAST(CAST(sum(t1.vatsum) As Int) AS Varchar(1)) end 'LineVat_LCNew',
Thanks Vinoth
Advertisement
Answer
You are casting your integer sum to varchar(1)
which means if the sum
is greater than 1 digit you won’t be able to place then in a varchar(1)
. Use varchar(10)
instead which means you can store upto 10 digits.
case when t1.VatGroup in('X6','X7') then '-' Else CAST(CAST(sum(t1.vatsum) As Int) AS Varchar(10)) end 'LineVat_LCNew'