Link to home
Start Free TrialLog in
Avatar of intelecorp
intelecorp

asked on

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
Avatar of randomjames
randomjames
Flag of United States of America image

What are you outputting it to?

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

Avatar of intelecorp
intelecorp

ASKER

Hi randomjames,
I am trying to export it to a fixed length flat text file. I am using a small utility to do this.
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.
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.
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?
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
ASKER CERTIFIED SOLUTION
Avatar of randomjames
randomjames
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..