how to prevent convert big numbers as varchar example 1444092 is 1.44409e+006
-
25-05-2021 - |
Domanda
this is my final query
select Codigo, Indicador,
case when Indicador like '%Porcentaje%' then cast((round((([Valor Censo Elegido]/@cantidad)*100),0)) as varchar(50))+' %' else cast([Valor Censo Elegido]as varchar(50)) end as [Valor Censo Elegido],
case when Indicador like '%Porcentaje%' then cast((round((([Valor Censo Actual]/@cantidad)*100),0))as varchar(50))+' %' else cast([Valor Censo Actual]as varchar(50)) end as [Valor Censo Actual]
--case when Indicador like '%Porcentaje%' then round((([Valor Censo Elegido]/@cantidad)*100),0) else ([Valor Censo Elegido]) end as [Valor Censo Elegido],
--case when Indicador like '%Porcentaje%' then round((([Valor Censo Actual]/@cantidad)*100),0) else ([Valor Censo Actual]) end as [Valor Censo Actual]
from #unionfinal
but big numbers convert something as 1.44409e+006 and i need when indicador contain word porcentaje this was calculated and char '%' was added, it converts but i got this bug
working on sql 2005
Soluzione
First, CAST to a DECIMAL number, then to a VARCHAR:
cast(cast((round(([Valor Censo Elegido]/@cantidad)*100),0) as decimal(50,0)) as varchar(50))+' %'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow