Solved

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

Posted on 2009-04-02
2
611 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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