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

SQL - Reduce column width in select statement

Is there a way in a SELECT statement that I can specify
how wide I want the display of a column to be? In other words,
I have several columns that are 50 positions wide (because
they are defined as char 50 ) but I want to display only the
first 10 positions. I obviously don't want to change the
size of the column in the table.  
0
vd
Asked:
vd
1 Solution
 
jboydCommented:
Example:

SET NOCOUNT ON
GO
CREATE TABLE SAMPLE (
      COLUMN1      CHAR(50)
)
GO
INSERT INTO SAMPLE ( COLUMN1 ) VALUES ( 'abcdefghijklmnopQRSTUVWXabcdefghijklmnopQRSTUVWX')
GO
PRINT "FIRST 10 CHARACTERS"
SELECT LEFT(COLUMN1, 10) FROM SAMPLE
GO
PRINT "LAST 10 CHARACTERS"
SELECT RIGHT(COLUMN1, 10) FROM SAMPLE
GO
DROP TABLE SAMPLE
GO
0
 
vdAuthor Commented:
Excellent. Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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