I'm trying to write a select statement for my autocomplete function(s). I want to take the prefix text from the given text box and pull the first 10 items who's beginning characters matches the prefix. I could probably figure it out on my own, but its getting only the first 10 matches that loses me. Any solutions?
Asked
Active
Viewed 36 times
1
-
3What have you tried so far? What did that give you? Why was that the wrong results? What do you think is the most likely reason it is wrong? – Lasse V. Karlsen Jan 21 '11 at 21:44
-
Um, I don't even know where to begin when it comes to stopping the query after so many matches have been found, so nothing – Nick Rolando Jan 21 '11 at 21:47
2 Answers
2
If you have the SQL working to pull the list back from the DB, just add "top 10" to the SQL... like
SELECT TOP 10 *
FROM EMPLOYEE
WHERE LName like 'Smi%'

John K.
- 5,426
- 1
- 21
- 20
1
Sql Server is case-insensitive unless you specify that as an installation option. That's a factor of the collation options. Here's an SO question on that topic: SQL Server check case-sensitivity?
To get the top ten results:
SET @searchValue = @searchValue + '%'
SELECT TOP 10 * FROM Items WHERE ItemName LIKE @searchValue ORDER BY ItemName

Community
- 1
- 1

Chris B. Behrens
- 6,255
- 8
- 45
- 71
-
Yeah..I just realized its not case sensitive to begin with. I edited my question, I apologize – Nick Rolando Jan 21 '11 at 21:52