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 2008 Forums
 Transact-SQL (2008)
 Convert number

Author  Topic 

amsad
Starting Member

17 Posts

Posted - 2011-02-22 : 03:59:28
Hi guys,

How to convert in sql,

example number
1) 43 to be 0043
2) 3 to be 0003

Any suggestion?need help..

Thank you,
Faizul





Can do.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-22 : 05:07:28
43 to 0043:
Source value comes from datatype INT?
select right('0000'+convert(varchar(30),YourIntColumn),4)

If you need to store this then a character datatype is needed...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

amsad
Starting Member

17 Posts

Posted - 2011-02-22 : 05:21:42
Hi webfred,

It is working excellent!
Thanks

Can do.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-22 : 05:27:25
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-24 : 04:08:41
You should do this in front end application. Otherwise, another method is

select replace(str(YourIntColumn),' ','0') from your_table

Madhivanan

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

- Advertisement -