Reputation: 25
I am trying to do padding (with *) to my select statement list so that all values will have same length upon retrieving.
Assuming my query is 'select distinct city from all_cities' and the list of values are boston, seattle, san francisco, san jose.
I want the output as
Can anyone provide inputs on this?
Thanks
Upvotes: 0
Views: 406
Reputation: 14376
select @MaxLength = max(len(city)) from all_cities;
select rpad(city, @MaxLength, '*') from all_cities;
As I'm clearly not a SQL whiz, I'm sure there's a way to combine this into a single select (not to mention my knowledge of built-in SQL functions is minimal)
Upvotes: 0
Reputation: 49260
You can use rpad
.
select rpad(city,15,'*') from all_cities;
Upvotes: 2