Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

How to do sql server string comparison of auto-trim varchar value?

Asked by Camellia Kleiber Apr 24, 2021 1.1K views 1 answer
Share

About this question

I was running a query for doing a comparison using = on an NVARCHAR field ignored the trailing space in the string (or auto-trimmed the value before comparison) but the same query using the like operator did not ignore the space. Collation being used is Latin1_General_CI_AS in 2012. Consider this SQL Fiddle: http://sqlfiddle.com/#!6/72262/4 Note that the like operator does not return a result for the trailing space

string, but the = operator does. Why is this? Bonus points: I am unable to replicate this on a VARCHAR field, I would have thought that a space would be handled in the same way in both data types - is this true?

How to do sql server string comparison?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.