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.
Author |
Topic |
dnf999
Constraint Violating Yak Guru
253 Posts |
Posted - 2006-12-21 : 09:01:21
|
Hi I have values in a table which I want as a set Length (7 digits).i.eValue Value I want------ ------------78 0000078980 00009803874 000387493049 0093049 Is there a function which I can use to do this, without writing a loop to add leading '0's...?Thanks in Advance |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2006-12-21 : 09:07:36
|
SELECT RIGHT('0000000' + LTRIM(RTRIM(STR(VALUE, 7))), 7)FROM YOURTABLEDuane. |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-21 : 09:09:00
|
[code]select right('0000000' + cast(Value as varchar(7)),7)[/code] Ditch, seems like you updated your boat! Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-21 : 09:13:40
|
1 If you use front end application, do format function thereeg in VBFormat(col,"0000000")2 Select col,Replace(Str(col, 7), ' ', '0') from tableMadhivananFailing to plan is Planning to fail |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-21 : 10:12:36
|
What if Value column is not integer?select Value, right('0000000' + Value, 7) from <yourcolumnnamehere>Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|