Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:20:38+00:00 2026-06-11T13:20:38+00:00

create table #temp(name nvarchar(10)) insert into #temp values(‘one’) select * from #temp where name

  • 0
create table #temp(name nvarchar(10))
insert into #temp values('one')
select * from #temp where name = 'one'
select * from #temp where name = 'one ' --one with space at end
drop table #temp

In the above I have used nvarchar for name.
My requirement is the result should be exist for the first select query, and it should not return for 2nd query. Do not trim the name. Advise me which data type can I use for this in sql server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:20:40+00:00Added an answer on June 11, 2026 at 1:20 pm

    Its not the data type that can resolve this issue. You need to see this article:
    INF: How SQL Server Compares Strings with Trailing Spaces

    SQL Server follows the ANSI/ISO SQL-92 specification (Section 8.2,
    , General rules #3) on how to compare strings
    with spaces. The ANSI standard requires padding for the character
    strings used in comparisons so that their lengths match before
    comparing them. The padding directly affects the semantics of WHERE
    and HAVING clause predicates and other Transact-SQL string
    comparisons. For example, Transact-SQL considers the strings ‘abc’ and
    ‘abc ‘ to be equivalent for most comparison operations.

    There are several ways to overcome this, one is to use Like.

    select * from #temp where name like 'one ' --one with space at end
    

    This will return no result.

    You should see this blog post: Testing strings for equality counting trailing spaces by AnthonyBloesch

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between: CREATE TABLE #temp ( [ID] INT) INSERT INTO #temp
Similar to Insert into a temp table from a stored procedure on Sql Server
I seem to be running into a problem with temp table garbage collection: CREATE
I have to select player name, Captain name from below mentioned table structure. table
Consider the following table: create table temp ( name int, a int, b int
Consider this snippet: CREATE TABLE #Temp ( Name varchar(100) ) GO DECLARE @Name varchar(100)
I have the following rows: CREATE TABLE #TEMP (id int, name varchar(255), startdate datetime,
How can i get result My Dream Table Result CREATE TABLE #temp( [count] int
I have temp table #xml that have 2 columns: CREATE TABLE #xml ( id
I have written a DB2 query to do the following: Create a temp table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.