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

  • Home
  • SEARCH
  • 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 7910797
In Process

The Archive Base Latest Questions

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

I have following code and it returns false for @B LIKE @A comparison in

  • 0

I have following code and it returns false for "@B LIKE @A" comparison in last statement.

I want to know that why Like is behaving in this way because as per my knowledge Like does the comparison on based of text not based upon data type.

DECLARE @Var1 Char(20)
DECLARE @Var2 VarChar(20)

SET @Var1 = 'X'
SET @Var2 = 'X'

SELECT 
@Var1 AS A,
@Var2 AS B,
LEN(@Var1) AS 'A Length',
LEN(@Var2) AS 'B Length',
CASE WHEN @Var1 = @Var2 THEN 'Yes' ELSE 'No' END AS 'A = B',
CASE WHEN @Var1 LIKE @Var2 THEN 'Yes' ELSE 'No' END AS 'A LIKE B',
CASE WHEN @Var2 LIKE @Var1 THEN 'Yes' ELSE 'No' END AS 'B LIKE A'
  • 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-03T13:00:23+00:00Added an answer on June 3, 2026 at 1:00 pm

    @A is of type CHAR(20), so it’s value is padded on the right with spaces to fill it out to a length of 20.

    The Len() function excludes trailing spaces, so both @A and @B show a length of 1 even though @A has been padded out with spaces.

    For comparisons, SQL Server follows ansi standards which require padding of strings to the same length before comparing, so @A and @B show as equal.

    The one exception to this is the LIKE predicate, which does not pad the strings to the same length if the trailing spaces are on the right.

    Ref: How SQL Server Compares Strings with Trailing Spaces

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

Sidebar

Related Questions

I have the following code that returns HTTP error 400 everytime I try to
I have the following code that works perfectly. It allows the user to 'like'
I have the following code $(document).ready(function() { $('a#slick-toggle').click(function() { $('#slickbox0').toggle(400); return false; }); });
I have the following code: $('.tagform').submit(function() { $('#tagsubmit-???').toggle('1000'); return false; }); And I have
The following code returns the error from the For Each loop. I have similar
I have multiple messages in SQS. The following code always returns only one, even
I have the following code on my Arduino that constantly checks for a serial
I have some jQuery code like this: // Called right away after someone clicks
I have the following code: <form action= method=get onsubmit=doRequest($('word').value); $('word').value=''; return false;> <input type=text
I have the following code: $(.perf-row).click(function(e) { if (e.target.tagName.toLowerCase() == a) { pageTracker._trackPageview($(this).attr(rel)); return

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.