In one of your tips you used two LIKE (well, actually 'NOT LIKE') operator statements joined by an AND. "SELECT * FROM Person.EmailAddress WHERE EmailAddress LIKE OR EmailAddress LIKE for reading WHERE row_num = 1 AND remotehostname LIKE '%-D' - I get 10,365 results which as you can see equals the sum of the individual queries for '%-UD' and '%-SD' - so, I have no clue why the 'OR' operator query gives me 19,902.īack To Top I think what you are looking for is the OR operator. WHERE row_num = 1 AND remotehostname LIKE '%-SD' - I get 3,276 results WHERE row_num = 1 AND remotehostname LIKE '%-UD' - I get 7,089 results WHERE row_num = 1 AND remotehostname LIKE '%-UD' OR remotename LIKE '%-SD' - I get 19,902 results For example taking an excerpt from my query (rather than the whole thing) - I am trying to find the number list of computer names that end on either '-UD' or '-SD' now if my WHERE line is: WHERE row_num = 1 AND (remotehostname LIKE '%-UD' OR remotename LIKE '%-SD')īen, thanks for getting back to me - I am aware or the 'OR' operator - however, I don't get accurate results. Can you try the following (note the brackets) As someone who has 20+ years working with SQL I'm very pleased to find new useful tricks.īack To Top - I think this might have to do with operator precedence and the AND condition being evaluated before the OR condition. If I have a like operator to look for a string within a column like this ‘%abc%’ does reverse still help? If not, is there another way to help with it?īig thanks, Ben. Which allows you to add wildcard characters in the WHERE clause as literal characters in your expressions. One other special clause with this operator is the ESCAPE clause Most other operators, the NOT clause can also be added to negate the condition beingĬhecked. The expressions can be columns or hard coded values,īoth of which can include wildcard characters (more on those below). Like any operator, the SQL Server LIKE operator goes between the two expressions/patterns Link, but I will be explaining in this tip the main points from the documentation. With that being said, it is always a good idea to read through the documentationĪnd become familiar with syntax and the different options available. It works is to just work through a bunch of examples to show what can be done with When learning about any operator, I find the best method for understanding how
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |