Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RIGHT JUSTIFY DATA IN FIELD 1

Status
Not open for further replies.

lyudmila

Programmer
Oct 18, 2002
54
US
Hello,
Is any way to right justify data in field on SQL Server?
 
The following code will right justify data in a column of width 20.

Select Right(Replicate(' ', 20) + Column_Name, 20)
From Table

Example: Right justifiy login names from syslogins

use master
Select Right(Replicate(' ', 40) + name, 40)
From syslogins Terry L. Broadbent - DBA
SQL Server Page:
If you want to get the best answer for your question read faq183-874.
 
Isn't
Select Right(Replicate(' ', 20-LEN(Column_Name)) +Column_Name, 20)
From Table
would be right?
But I run both ways, but did not get desirable result.

Data type in this field is char(13), but it's actualy decimal and represent Amount
When I open table in SQL Server EM my data in this column is still in the middle and not alighed

 
Running a SELECT query doesn't change the data in the table. It only displays the data right justified in the result set of SELECT. Do you want to update the table? If so use an UPDATE query.

Update Table_name
Set column_name=replicate(' ',13-len(column_name)) + column_name

To zero fill replicate '0' rather than ' '. Terry L. Broadbent - DBA
SQL Server Page:
If you want to get the best answer for your question read faq183-874.
 
I used this syntax only for example and modified your example. I create new table with "SELECT INTO" . It should create table with right justified field. if syntax is correct.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top