Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Modifying column size (output)?

Modifying column size (output)?

Modifying column size (output)?

Hi, I apologize if this is a very basic question (it seems like it should be), but for the life of me, I have been unable to locate a command that will change the size of an output column.

For example, let's say that I'm selecting column A, which is of type VARCHAR(50), but I'd only like to show the first 10 characters of the column in my output table. How can this be done?


RE: Modifying column size (output)?

You could use SUBSTRING:

select substring(A from 1 for 10) from tablename

RE: Modifying column size (output)?

Ok, I did a poor job of explaining what I'm trying to do. I want to limit the size of the output field (not just the number of characters that are output).

For example, let's say I want to limit my CITY field to 15 characters (it is declared as VARCHAR(40)). Let's suppose there's also a COUNTRY field (VARCHAR(10)).

I want this output:

CITY            COUNTRY
=============== ==========
Stockholm       Sweden
Berlin          Germany

instead of:

CITY                                     COUNTRY
======================================== ==========
Stockholm                                Sweden
Berlin                                   Germany

I tried substring, but it only limited the number of characters output (and kept the output field size the same).

Any help appreciated.


RE: Modifying column size (output)?

Ack, I should have checked the formatting before posting. The COUNTRY column name and its data are supposed to be in line (in both cases) with the first "=" after the space.

Point is, I'm trying to control the length of the columns so output is a lot more compact.

RE: Modifying column size (output)?

You can use:

select cast(A as varchar(10)) from tab

or possibly:

select cast(substring(A from 1 for 10) as varchar(10) from tab

The first statement should give a warning if non-blank characters are truncated while the second one will silently do this.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close