ousoonerjoe
Programmer
What is the best way to pad a field (Left or Right) in SQL?
Flat file outputs are often fixed width and in some cases require very little adjusting of the data. If it can be generated via Stored Procedure in DTS, then that makes my life all that much better. Problem is the formatting.
For an 11 digit Money field I have (could be used for strings, too):
But as you can see this is very limited and clumsy. I was hoping to find something like VB's Format function, but SQL's FORMAT isn't exactly flexible.
I found a lot of topics that pertained to formatting, but nothing about padding for a fixed width file output. I welcome any suggestions you may have.
Thank you.
"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
Flat file outputs are often fixed width and in some cases require very little adjusting of the data. If it can be generated via Stored Procedure in DTS, then that makes my life all that much better. Problem is the formatting.
For an 11 digit Money field I have (could be used for strings, too):
Code:
[Amount] =CASE WHEN td.Amount > 0 THEN
RIGHT(REPLACE('00000000000' + CAST(td.Amount AS VARCHAR(11)),'.',''),11)
ELSE
'-' + REPLACE(RIGHT(REPLACE('00000000000' + CAST(td.Amount AS VARCHAR(11)),'.',''),10),'-','0')
END
I found a lot of topics that pertained to formatting, but nothing about padding for a fixed width file output. I welcome any suggestions you may have.
Thank you.
"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.