help with sql server '05 query statement
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 m开发者_JS百科atches that loses me. Any solutions?
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%'
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
精彩评论