For the purposes of comparison, trailing blanks are ignored. For example, “Dirk” is the same as “Dirk ”. In comparing dates, < means earlier than, and > means later than. Place apostrophes or quotation marks around all char, nchar, unichar, unitext, varchar, nvarchar, univarchar, text, and date/time data:
select * from titleauthor where royaltyper < 50
select authors.au_lname, authors.au_fname from authors where au_lname > "McBadden"
select au_id, phone from authors where phone != "415 658-9932"
select title_id, newprice = price * 1.15 from pubs2..titles where advance > 5000
For more information on entering date and time data, see Chapter 7, “Adding, Changing, Transferring, and Deleting Data.”
not negates an expression. Either of the following two queries finds all business and psychology books that have advances of less than 5500. Note the difference in position between the negative logical operator (not) and the negative comparison operator (!>).
select title_id, type, advance from titles where (type = "business" or type = "psychology") and not advance >5500
select title_id, type, advance from titles where (type = "business" or type = "psychology") and advance !>5500
Both return the same result set:
title_id type advance -------- ------------ -------- BU1032 business 5,000.00 BU1111 business 5,000.00 BU7832 business 5,000.00 PS2091 psychology 2,275.00 PS3333 psychology 2,000.00 PS7777 psychology 4,000.00 (6 rows affected)