Hello,
I'm writing a query that will hit our database, retrieve certain fields from it, then output it as a left justified, 50 character fixed length field.
I'm not sure if its possible to do this in SQL. I know that I could just write an app that runs the query, then writes the output in the correct format, but I'd much rather skip that step and be able to do it straight from the database.
So, can anyone show me how to create the output as a fixed length field? And then make it left justidfied?
Thank you.
EDIT:
Nevermind, someone at work stumbled upon the answer. Use the replicate function, so it would look like this:
Field1 + REPLICATE(' ', 50 - LEN(Field1))
That will set it to be left justified and be padded to 50 spaces with spaces.
Thanks to anyone who started looking for an answer for me!
I'm writing a query that will hit our database, retrieve certain fields from it, then output it as a left justified, 50 character fixed length field.
I'm not sure if its possible to do this in SQL. I know that I could just write an app that runs the query, then writes the output in the correct format, but I'd much rather skip that step and be able to do it straight from the database.
So, can anyone show me how to create the output as a fixed length field? And then make it left justidfied?
Thank you.
EDIT:
Nevermind, someone at work stumbled upon the answer. Use the replicate function, so it would look like this:
Field1 + REPLICATE(' ', 50 - LEN(Field1))
That will set it to be left justified and be padded to 50 spaces with spaces.
Thanks to anyone who started looking for an answer for me!
Last edited: