March 6, 2006 at 4:31 pm
Is there a nice way to turn, eg, 3 into '03', without a bunch of casting, or a UDF (which I fear will slow things down?
Eg, a nice builtin of which I'm ignorant, ZeroExtend(int base, int width)
?
March 6, 2006 at 5:47 pm
How about ...
declare @y int
set @y = 3
select substring(convert(varchar(3), @y + 100),2,2)
It's not a builtin, but it doesn't look too painful.
March 6, 2006 at 5:50 pm
select right('00' + convert(varchar(2), 3), 2)
March 6, 2006 at 5:56 pm
I figured out a replicate call, but it required wrapping it in a case to avoid passing a negative to the replicate. That right/convert combo is more succinct. Thanks.
March 6, 2006 at 6:24 pm
Or...
SELECT REPLACE(STR(3,2),' ','0')
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply