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
 General SQL Server Forums
 New to SQL Server Programming
 fill with 0 before

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2011-11-17 : 02:19:12
HI,
I need the query for below
I have an nvarchar(10) filed
I have values less than 10, and i want them to be filled with 0 before
Ie:
150672
122670
54756
128756
97113
should be saved as

0000150672
0000122670
0000054756
0000000056
0000097113


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-17 : 03:59:37
RIGHT('0000000000' + field,10)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2011-11-17 : 04:22:39
It works cool !
Thanks a Lot visakhm

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-17 : 04:38:20
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-21 : 03:05:41
Alternatively, if you want to show data in front end application, use format functions there

Another method is


select replace(str(col,10),' ','0') from table

Madhivanan

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

- Advertisement -