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 |
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2008-10-08 : 17:46:11
|
i have field in a table that has data in the following format 134567245298what is need to do is append the field with 0's in the following manner in a select statementif one digit ex: 0001if two digits ex:0034if three digits ex:0567how can this be done?thanks in advance |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-08 : 17:52:09
|
[code]declare @temp table(ID bigint IDENTITY(1,1) NOT NULL,nums varchar(4));INSERT INTO @TEMP (nums)select 1 UNION ALLselect 34UNION ALLselect 567UNION ALLselect 2UNION ALLselect 45UNION ALLselect 298;select nums from @TEMP;select right('0000'+nums,4) as nums from @TEMP[/code]RESULTS:[code]nums ---- 134567245298(6 row(s) affected)nums ---- 000100340567000200450298(6 row(s) affected)[/code] |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
akpaga
Constraint Violating Yak Guru
331 Posts |
|
hanbingl
Aged Yak Warrior
652 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-09 : 03:15:58
|
If you want to show formatted numbers in front end, use Format function thereMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|