?
Solved

Right/ Left Justify

Posted on 2003-03-05
5
Medium Priority
?
1,263 Views
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
fieldname
           xxxx
0
Comment
Question by:singhrkp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:gletiecq
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?

Greg
0
 
LVL 6

Accepted Solution

by:
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
0
 
LVL 5

Expert Comment

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

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

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

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 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