Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to convert numeric to fix length string

Author  Topic 

pacolim
Starting Member

11 Posts

Posted - 2010-05-06 : 23:43:05
May I know what is the easiet way to convert

123 (numeric) into 0000123 (varchar)

in sql server 2005?
It can be done in Visual Studio using format fucntion, but this function is not supported in sql server

Thank you.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-06 : 23:50:49
[code]
select right(replicate('0', 7) + convert(varchar(10), 123), 7)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-07 : 07:00:50
quote:
Originally posted by pacolim

May I know what is the easiet way to convert

123 (numeric) into 0000123 (varchar)

in sql server 2005?
It can be done in Visual Studio using format fucntion, but this function is not supported in sql server

Thank you.


If you want to show data in .NET, do the formation there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -