I have tried the following SELECT
:
SELECT (2*3) as Resultado
i got this
Resultado
6
I need this result:
Resultado
06
If I multiply like this:
SELECT (12*2)
Resultado
24
I want the result to only contain two digits always, how do I do that?
06
it doesn't exist as a number, so to get your result you need to first convert it to a string. A simple way would be the following:Now, you must consider that if the result of the multiplication is
100
, for example, then you will obtain'00'
(or'0*'
) as a resultThere are the LPAD and RPAD functions that fill a string with the character you specify until it reaches the desired length (LPAD does it from the left and RPAD from the right:
LPAD( string_to_modify , desired_length , padding_character )
In your case:
SELECT LPAD(2*3,2,0) as Result
This will give us that Result is 06
I do not know if these functions or something similar exist on your platform. You'll have to try.
A response similar to that of the good brother Lamak
It generates:
Reference: http://devjoker.com/contenidos/articulos/358/Formatear-numeros-en-SQL-Server.aspx