Solved

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

Posted on 2007-12-06
10
2,172 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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