Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whe I retriev char from db it brings with spaces

Status
Not open for further replies.

mooniron

Programmer
Dec 15, 2002
26
TR
Hi all. When I want to get data from a SQL table, which is char type, sql server gives me that data with spaces. For example my coloumn is: name char(20) But if the data in this colomn is 13 length, query takes the left 7 length space with itself. How can I resolve this problem. Thank you and best wishes.
 
char means fixed length. I.e. the value is padded with space if it shorter than the declared length. Use a varchar data type instead.

You can remove the trailing spaces by using the rtrim function in your select statement.

select rtrim(c) from t
 
you can declare the columns as VARCHAR if you don't need the spaces.

Note compairing a VARCHAR column to a CHAR column often does not come up with a match because of the white spaces in the CHAR column.
 
More , there is also ltrim function , which trims left spaces... ________________________________________________________________________________
If you do not like change, get out of the IT business...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top