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
 Formatting Data

Author  Topic 

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2006-12-05 : 09:25:52
Hi all,

I have data in a SQL Server table of type varchar(6). Each record in the column is a number of 2, 3 or 4 digits.

e.g. 22, 130, 1000, 60 etc...

I want to update all the values in the column so that they are always 4 characters long and have leading zeros.

e.g. 0022, 0130, 1000, 0060 etc...

How could I go about doing this?

Thanks
Kabir

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-05 : 09:27:58
update yourtablenamehere
set yourcolumnnamehere = right(replicate('0', 4) + yourcolumnnamehere, 4)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-05 : 09:48:35
FYI, Formatting is front end issue. If you use front end application like VB6, you can use

Format(data,"0000")

Madhivanan

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

- Advertisement -