pvsbandi
asked on
Adding spaces to the string
Hi,
I have a string field with values as long as 50 characters and as small as 2 characters or some times, a blank value.
But i need to display this field so that it displays 10 characters only.
But if it is less than 10 characters, then the first space characters should be appended to the actual field value.
Example : Field = 'ABCDEFGHIJKL'.
Then it should be substr(Field,1,10) which gives me 'ABCDEFGHIJ'.
But if Field = 'ABCD'
Then it should display ' ABCD' ( 6 spaces followed by the field value).
If the field has a null value, the it should still maintain those 10 spaces.
Please help.
I have a string field with values as long as 50 characters and as small as 2 characters or some times, a blank value.
But i need to display this field so that it displays 10 characters only.
But if it is less than 10 characters, then the first space characters should be appended to the actual field value.
Example : Field = 'ABCDEFGHIJKL'.
Then it should be substr(Field,1,10) which gives me 'ABCDEFGHIJ'.
But if Field = 'ABCD'
Then it should display ' ABCD' ( 6 spaces followed by the field value).
If the field has a null value, the it should still maintain those 10 spaces.
Please help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You guys rock!
ohoh...
Upon further review.....
Momi's simpler query for the right justified string is a better solution than what I posted. Sorry.
SELECT case when length (string) >= 10 then left (string, 10)
else right (' ', coalesce (string, ''))
end
Kent
select left ( ' ' || coalesce(your_column, ''), 10)
from your_table