Blank space in the end of a nvarchar field

Posted on 2009-02-12
Last Modified: 2012-05-06
I created a table in SQL Server 2005 and when I enter a string text in a field set to nchar(15) and allow nulls, it adds empty space at the end so to fill the 15 characters. Gives me a headache trying to compare.

Question by:Papote
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    use nvarchar instead of nchar.
    LVL 57

    Accepted Solution

    If you use datatype as NChar, then it will pad up the empty values with empty space. But if you use datatype as Nvarchar empty spaces will be left and hence you will have only your data.

    Hence if you use NChar, you have to trim your data and then use for join or comparison or you can use Nvarchar too.

    Author Comment

    OOps... Thanks.
    Was using trim() as a fix. But completely forgot about nvarchar.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now