Right/ Left Justify

Posted on 2003-03-05
Medium Priority
Last Modified: 2011-10-03
I want to know that how can we right / left justify a text field for example if we have char/varchar field of width 15 and only 4 chars exists in table so when we use select fielname from tablename then fieldname must be right justifies with blank padded at its left side.

It should look like following
Question by:singhrkp

Expert Comment

ID: 8073829
Do you want the database to prepend blanks in order to right-justify?  Or is this a question about how to make the application display data differently?


Accepted Solution

DaniPro earned 200 total points
ID: 8078282
if you want right justify your text use this SQL

SELECT RIGHT(SPACE(15) || YourField, 15) FROM YourTable

otherwise if you want left justify your text use this SQL

SELECT LEFT(YourField || SPACE(15), 15) FROM YourTable

Expert Comment

ID: 8089677
I guess you need a + operator ..

select left((space(15) + convert(varchar, myField)),15) from tablename

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you have a site with just static html pages or a dynamic database-driven one, this step-by-step migration guide will help you get started with your new DV server. This guide is by no means comprehensive but it should cover the basics to get …
Good news! Plesk 12.5 (with update #28 and above) now includes support for HTTP/2. This is a major update to HTTP1.1, which is over 15 years old. Read below to learn how to enable HTTP/2 on your Media Temple DV with Plesk.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question