?
Solved

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

Posted on 2009-04-02
2
Medium Priority
?
618 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
udaya kumar laligondla earned 750 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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