Home > Transact-SQL > Transact-SQL: Compare strings in SQL and spaces

Transact-SQL: Compare strings in SQL and spaces

13:00

Marek Śliwiński Leave a comment Print This Post  (535) Go to comments

Just a quick reminder/note. What will be the result for below string comparision? What do you think?

IF ('   ' <> '')
	print 'different'
ELSE
	print 'equal'

If you answered ‘different’ then you are wrong :) The result will be ‘equal’. Why?
Because SQL ignores trailing spaces when comparing strings.

Share and Enjoy:
  • DotNetKicks
  • Digg
  • del.icio.us
  • Wikio IT
  • Google Bookmarks
  • Facebook
  • Print
  1. No comments yet.
  1. No trackbacks yet.

Subscribe without commenting