• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2432
  • Last Modified:

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

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
intelecorp
Asked:
intelecorp
  • 4
  • 4
1 Solution
 
randomjamesCommented:
What are you outputting it to?

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

0
 
intelecorpAuthor Commented:
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
 
randomjamesCommented:
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
Industry Leaders: 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!

 
intelecorpAuthor Commented:
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
 
randomjamesCommented:
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
 
intelecorpAuthor Commented:
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
 
randomjamesCommented:
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
 
intelecorpAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now