Sunday, March 11, 2012

Displaying numbers like 05 instead of 5

Hi,
In my database I have a table with two digit integers.
When I make a query, I would like see something like this
01
02
03
04
05
06
...
10
11
12
instead of
1
2
3
4
5
6
...
10
11
12
Is there a function for doing that?
Thanks!declare @.i int
set @.i = 3
select @.i, right('00' + convert(varchar(4),@.i),2)
-- --
3 03
Roy Harvey
Beacon Falls, CT
On Mon, 03 Jul 2006 12:35:49 -0400, LEM <anonymous@.nospam.com> wrote:

>Hi,
>In my database I have a table with two digit integers.
>When I make a query, I would like see something like this
>01
>02
>03
>04
>05
>06
>...
>10
>11
>12
>
>instead of
>1
>2
>3
>4
>5
>6
>...
>10
>11
>12
>Is there a function for doing that?
>Thanks!|||Thanks Roy!|||select right( '00' + convert(varchar(2),ColumnName),2)
example
declare @.i int
select @.i =9
select right( '00' + convert(varchar(2),@.i),2)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
LEM wrote:
> Hi,
> In my database I have a table with two digit integers.
> When I make a query, I would like see something like this
> 01
> 02
> 03
> 04
> 05
> 06
> ...
> 10
> 11
> 12
>
> instead of
> 1
> 2
> 3
> 4
> 5
> 6
> ...
> 10
> 11
> 12
> Is there a function for doing that?
> Thanks!|||Okay so I was fashionably late since Roy Harvey already gave the answer
(even used the same variable name)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
SQL Menace wrote:
> select right( '00' + convert(varchar(2),ColumnName),2)
> example
> declare @.i int
> select @.i =9
> select right( '00' + convert(varchar(2),@.i),2)
> Denis the SQL Menace
> http://sqlservercode.blogspot.com/
>
> LEM wrote:

No comments:

Post a Comment