Solved

nchar(20) column adding spaces on to end of data

Posted on 2009-04-02
2
594 Views
Last Modified: 2012-05-06
I have a column in a SQL Server database called position and it is nchar(20).

When I add text into the column using SQL Server management studio, it appears to put spaces onto the end of the data

This means that "Director" becomes "Director     " (just adding " to show what I mean.

When I go to select from position colum where position = "Director" it does not find the record.

How do I stop these extra spaces being added ?
0
Comment
Question by:dkmarsh
2 Comments
 
LVL 12

Accepted Solution

by:
udayakumarlm earned 250 total points
ID: 24057204
use NVarchar or Varchar instead of NChar.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24057338
Yes. that's the basic difference between Nvarchar and NChar.

If you set a datatype as Nchar(20) , Server allocates empty spaces for each and every value and if you give some values it will occupy the first 5 or 10 bytes based upon the length of the value either 5 or 10.

If you set the datatype as Nvarchar(20), memory will be dynamically allocated based on the input string and hence only 5 or 10 bytes for a string of size 5 or 10.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question