I need to display user's in an application I am building by the first letter of their last name. Would it be better to query with LIKE, or directly check the first letter?WHERE U.LastName LIKE @FirstLetter + '%'WHERE LOWER(SUBSTRING(U.LastName, 1, 1)) = LOWER(@FirstLetter)
The DB is not case-senstive so technically the LOWER()s aren't required. Also, what if I needed a range, say "An" through "Az"? The best I could come up with was this:WHERE ASCII(LOWER(SUBSTRING(U.LastName, 1, 1))) >= ASCII(LOWER(@StartFirstLetter)) AND ASCII(LOWER(SUBSTRING(U.LastName, 1, 1))) <= ASCII(LOWER(@EndFirstLetter)) AND ASCII(LOWER(SUBSTRING(U.LastName, 2, 1))) >= ASCII(LOWER(@StartSecondLetter)) AND ASCII(LOWER(SUBSTRING(U.LastName, 2, 1))) <= ASCII(LOWER(@EndSecondLetter))
Thanks,Steve