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)
 add zeros at the beginning

Author  Topic 

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-04-30 : 13:30:58
hi there i have a table

called "products"


product code
apple 23
grape 7



etc i need to add to all my codes, zeros at the beggining
untill complete a lenght=6


thats the table that i neeed

product code
apple 000023
grape 000007

thanks for your help

many many thanks

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-04-30 : 13:59:27
what datatype is that column?
will the final length of that field always be 6?
<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-04-30 : 13:59:54
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=162392&SearchTerms=pad,left









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-30 : 14:26:21
RIGHT('000000' + cast(code as varchar(6)),6)

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

Go to Top of Page

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-04-30 : 16:57:50
thanks a lot for everyone
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-01 : 10:10:55
wc

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

Go to Top of Page
   

- Advertisement -