First I am converting the value from the table as integer like
cast(convert(int, isnull(b.temp,0)) as varchar(500))
and then I would like to output values as written below for example
1 as 001
12 as 012
123 as 123
-1 as -001
-15 as -015
-234 as -234
and if length of the integer value is more than 3 then do not display any value or remove it.
If integer has Minus(-) sign then it is not part of the length
so -001 is consider as length 3
so 001 and -001 is acceptable as length 3
How can I do that?
There really is no efficient way to do this, but I understand there are situations where this needs to be done. I would probably go about it with something like this turned into a function.
This really should be done in code and not sql.