Skip to main content
Participant
November 14, 2006
Question

MS SQL character compare question?

  • November 14, 2006
  • 2 replies
  • 509 views
Can anybody please tell me how to compare 'Al Sarif' and 'Al sarif' in MS SQL server?Thanks!
    This topic has been closed for replies.

    2 replies

    ShijingqAuthor
    Participant
    November 14, 2006
    Is there anything similar in SQL server
    as In Oracle
    select 'Al Sarif'='Al sarif' from dual;
    Participating Frequently
    November 14, 2006
    Compare how? Ignoring case?
    Participating Frequently
    November 14, 2006
    If your database is set to be case insensitive, then you might want to cast your strings to binary if you want to compare them to see if they are exactly the same, including case. For instance, if your_field contains 'Al Sarif' and you don't consider 'Al sarif' a match, you could do something like this:

    SELECT whatever
    FROM your_table
    WHERE CAST(your_field AS binary) = CAST('Al sarif' AS binary)

    Otherwise, you will return rows regardless of case if your database is set up that way.

    Phil
    Participating Frequently
    November 14, 2006
    How about this?

    SELECT 1 AS Expr1
    WHERE CAST('Al Sarif' AS binary) = CAST('Al sarif' AS binary)
    will will not return any rows.....

    SELECT 1 AS Expr1
    WHERE CAST('Al Sarif' AS binary) = CAST('Al Sarif' AS binary)
    this will return a 1....

    SELECT 1 AS Expr1
    WHERE 'Al Sarif' = 'Al sarif'
    this will also return a 1 if your database is set up as case insensitive.

    Phil