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
 Ideas anyone

Author  Topic 

stumbling
Posting Yak Master

104 Posts

Posted - 2007-04-09 : 00:48:49
Hi all
I am fishing for ideas on the following scenario and hope someone can point me in the best direction.

I create a new table and insert data from relevant other tables but i want to set the data in the new table colums to set widths that have leading zeros where applicable.
I.E the new table column is varchar (10) the data going in to the column is coming from another table where the size was varchar (8) but the data was only 2 characters in size so i want to pad it out to the full new varchar (10) with leading zeros if that makes sence.

I am really just trying to get some ideas on the best possible way to do this thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-09 : 00:54:01
[code]
insert into newtable(newcol)
select right(replicate('0', 10) + oldcol, 10)
from oldtable
[/code]


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-10 : 06:41:04
1
If you want to show numbers with leading zeros and if you use front end application, you can easily use format function there
2
other way is '00000000'+oldcol if all oldcol have length 2

Madhivanan

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

- Advertisement -