Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now