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 |
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-09-13 : 04:38:18
|
Hi,I need to create a fixed width flat file and fill the columns with special characters if they are not wide enough. For text-type data I typically use something like thisSELECT LEFT(myColumn + SPACE(50), 50) to create a fixed width column of 50 characters but sometimes I need to fill with differentcharacters than space. Any nice ways to do this?--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-09-13 : 04:41:06
|
use replicate() KH |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-09-13 : 04:41:24
|
REPLICATE instead of SPACE ? Kristen |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-09-13 : 05:20:15
|
Ah...hehe...I actually looked at REPLICATE in BOL but the example replicated a columnname in the adventureworks database like this:SELECT REPLICATE (LastName, 2) AS "LastName Twice" FROM EmployeesResult set:--------------FunkFunkI didn't see that I could use it for what I wanted...how stupid can you get!  --Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-09-13 : 05:50:50
|
"I didn't see that I could use it for what I wanted"No kidding - what use is a "LastName Twice" column anyways?? Any, more seriously, why have they switched from [ColumnName] back to the old "ColumnName" style?Kristen |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-09-13 : 05:58:27
|
"I didn't see that I could use it for what I wanted"Why can't you use REPLICATE?Select LEFT(myColumn + Replicate('#',50), 50) Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
Kristen
Test
22859 Posts |
Posted - 2006-09-13 : 06:25:09
|
Lumbago can, but it wasn't obvious to him from BoL - and I agree based on that example!Kristen |
 |
|
|
|
|
|
|