SQL Server - Justify data in columns

I have Column A with Sales Persons ID with Column B the amount of units sold. My problem is that the output math is correct, however the look is bad. (Select Column A, Column B from tblSales_Data)

Current Results
Column A   Column B
A123456  35

Want
Column A  Column B
A123456              35

So the issue is that the 35 untis sold lines up right next to the Sales Person, I want to know how to right justify?
SeTechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
SQL Server is a database, and cosmetic rendering is not in it's scope, so SQL Server by itself is not designed to *do* left or right justify, at least not numeric data types.

If you absolutely frEEaking have to right justify in SQL, then you'll have to convert to a character field, add leading spaces, then take the right-most x number of characters, like this
SELECT ColumnA, RIGHT(SPACE(20) + CAST(ColumnB as varchar(10)), 20) 

Open in new window


Explain what your are using to display this data, and why you want it to look a certain way.
0
PortletPaulfreelancerCommented:
Agree with Jim, this is NOT the role of SQL.

Even padding text with spaces can fail because you have to use a non-proportional font to render the output, and SQL does not control fonts at all.

Are you trying to output this as a web page? or as a printed report?

The reason for asking isn't that I want the specific answer, but to indicate that it is the role of html or of a report writer to handle the rendering depending on what you are trying to achieve.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SeTechAuthor Commented:
Thanks for the answer and additional education, which I will certainly consider.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.