1

I'm working with VS2010 and asp.net and build a SQL Server Database with some int and char values.

My problem is, that the char(50) automatically fills the unused chars with whitespaces like:

"foo           " 

What can i do to get only "foo"?

1
  • Yes, that's the way CHAR(x) is defined in SQL Server - use VARCHAR instead if you want to have string only as long as needed. See the SQL Server Books Online documentation: msdn.microsoft.com/en-us/library/ms176089.aspx Commented Aug 9, 2010 at 16:26

2 Answers 2

7

Change it to varchar(50). The char(50) data type will fill the remaining characters of the field with spaces.

Sign up to request clarification or add additional context in comments.

Comments

2

It's not Visual Studio that's adding the white spaces, but your datatype.

Char is fixed-length, while varchar is variable length. Char will pad the remaining text with spaces up to your field length.

You can see more information about SQL datatypes here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.