Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2010

    Unanswered: Strangest thing... Getting different results when checking for string in a query.


    I cannot see nor understand why one query would return something different than the other...

    Here's the queries:
    DECLARE @searchString NVARCHAR(255)
    SET @searchString = 'EHA'
    SELECT, FROM users as t1 
    WHERE LIKE  '%' + 'EHA' + '%')
    SELECT, FROM users as t1 
    WHERE LIKE  '%' + @searchString + '%')
    The first query (select-statement), where I've manually written 'EHA' returns 6 rows, while the second query returns 5 rows, it is missing on the name "EHAA". The "Name" field is of type varchar(4), not null.
    Image of the results:



    The field is of type varchar... I've declared a nvarchar-variable, so problem is "solved", but still not understand why the nvarchar did not work. I've also tried with adding a TRIM to the search string as follows:
    SET @searchString = RTRIM(@searchString);
    SET @searchString = LTRIM(@searchString);

    But it resulted in the same... Still do not understand why it would fail on "EHAA" and not the others...Probably because it began with "EHA", and it skipped the first character in the string, somehow...
    Last edited by ManyTimes; 02-18-13 at 10:20.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts