Solved

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

Posted on 2009-04-02
2
582 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
Comment Utility
use NVarchar or Varchar instead of NChar.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

12 Experts available now in Live!

Get 1:1 Help Now