Solved

How can I right or left justify text in SQL tables?

Posted on 2007-12-06
10
2,243 Views
Last Modified: 2008-09-20
I am trying to justify the text in some tables to right justify or left justify. I am using a utility to export the data from tables to a fixed length file format and on this output I need some of the fields justified. Any assistance is greatly appreciated.
Regards
0
Comment
Question by:intelecorp
[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
  • 4
  • 4
10 Comments
 
LVL 3

Expert Comment

by:randomjames
ID: 20421924
What are you outputting it to?

Wouldn't that formatting be applied on the output mechanism (perhaps a report) instead of the database?

0
 

Author Comment

by:intelecorp
ID: 20421984
Hi randomjames,
I am trying to export it to a fixed length flat text file. I am using a small utility to do this.
0
 
LVL 3

Expert Comment

by:randomjames
ID: 20422147
That does not make sense to me.

What is the exported text file being used with? That kind of formatting should be done by the application using the data.

A flat text file just doesn't hold those kinds of instructions (justify left or right). You could maybe rig that with XML, but that's a whole different can of worms.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:intelecorp
ID: 20422262
The exported file is simply a flat file fixed length. My vendor requires me to have the dtaat formatted such that any fields containing numeric characters are to right justified and any fields containing alpha-numeric characters are to be left justified. Its just the format my vendor requires for processing the data on their end.
I am using a small utility that exports information from MS SQL tables to a text file, but I cant get it to do the above.
0
 
LVL 3

Expert Comment

by:randomjames
ID: 20422361
Okay, well that's not too weird then.

If your numeric fields are left-justified it's because they are being exported as character values instead of numeric values I am pretty sure.

Can you convert the character value into a numeric value in your SQL before you export? Maybe the utility you are using has an option for this?
0
 

Author Comment

by:intelecorp
ID: 20422483
Yes I tried to convert to INT instead of CHAR but then I cannot specify field length, and since its fixed length, I have to preserve the field length so that the output is spit out properly
0
 
LVL 3

Accepted Solution

by:
randomjames earned 50 total points
ID: 20423638
Okay, you need more than just justification, you need to pad your values and put them together in a string and export that. I don't know the utility you are using, but I would be surprised if it accommodates this need.

If you were just using straight SQL in the database I would suggest that you write a stored procedure to take in parameters of the string you need to pad and the number of spaces it needs to be and returns the padded string.

Not exceptionally simple but do-able...
0
 

Author Comment

by:intelecorp
ID: 20423735
Yes.. thats a possibly solution, given that the data in the tables was of fixed length as well.. the strings vary.. for instance..a field length could be 40.. but the actual data could vary from 10 characters to 40..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 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