Groups | Blog | Home
all groups > sql server (alternate) > march 2004 >

sql server (alternate) : How do I add a leading zero to a column of data in a table



cclinger NO[at]SPAM thompsoncoe.com
3/12/2004 2:05:05 PM
Hi,

I have an existing table with over 8,000 rows that I need to add a
leading zero to a column of data. (i.e. current no: 2000, with
leading zero: 02000).
This data lives on in MS SQL 7.0 on a Windows 2000 server.
Thanks

Erland Sommarskog
3/12/2004 11:07:12 PM
Chad (cclinger@thompsoncoe.com) writes:
[quoted text, click to view]

I assume that this is a character column?

UPDATE tbl
SET col = '0' + col

I have here not consider the case that you might have leading spaces.
If this answer is not satisfactory, please be more specific.


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
mountain man
3/13/2004 4:08:43 AM
[quoted text, click to view]


update existing_table
set target_column = '0' + cast(target_column as varchar)
from existing_table



AddThis Social Bookmark Button