A string in SQL Server with spaces at the end of the comparison

Source: Internet
Author: User

When comparing strings in SQL Server if the end of the string is a space then SQL Server ignores those spaces and compares them directly.

declare @a nvarchar( 50 );set @a =N ‘happycat1988‘ declare @b nvarchar( 50 );set @b =N ‘happycat1988 ‘①: "= The trailing space will be ignored to return true" if ( @a = @b      select ‘True‘ as 直接等号比较 else      select ‘False‘ as 直接等号比较②: "Like will return false" if ( @a like @b      select ‘True‘ as like比较 else     select ‘False‘ as like比较③: The Len function also ignores the trailing spaces, but Datalength does not "④:" In the SELECT statement also ignores spaces "select * from Sysc_user where user_code like ' 000065 ' this statement will query out User_c    Ode entries with spaces after 000065 and 000065 are added. If you are using User_code to associate with other tables. May cause lazy loading. Original Digest from https://www.2cto.com/database/201509/441544.html

A string in SQL Server with spaces at the end of the comparison

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.