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 |
|
SexyChick
Starting Member
6 Posts |
Posted - 2006-01-25 : 13:21:16
|
| I am new to writing sprocs so forgive me if this is trivial. I am selecting fields from a table and placing them into a temp table in row format. (Row 1 in temp table is the first row in a file that will be created using DTS package). My question is: How can a format a field that I have selected that only has, say 3 chars, into a value of 5. Ex: field in DB = aaaI need to format it as: 2 spaces + aaaBut the length of the value will be varying from record to record. |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-25 : 13:53:39
|
| TrySelect REPLICATE(' ', 2 - DATALENGTH(CAST(F1 AS VARCHAR))) + convert(varchar, F1) from Tbl |
 |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2006-01-25 : 15:02:19
|
Or thisDECLARE @abc varchar(3)SET @abc = 'abc'SELECT REVERSE(CONVERT(char(5),REVERSE(@abc))) Beauty is in the eyes of the beerholder |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
AndyB13
Aged Yak Warrior
583 Posts |
Posted - 2006-01-25 : 15:04:40
|
I have, [hic] bottle of Becks in hand.....Its been a while that i forgot how to post!Beauty is in the eyes of the beerholder |
 |
|
|
SexyChick
Starting Member
6 Posts |
Posted - 2006-01-25 : 15:27:55
|
| Thanks Guys! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-27 : 01:11:15
|
One more methodDECLARE @abc varchar(3)SET @abc = 'abc'select space(5-len(@abc))+@abc Andy, Where were you for long time? MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|