-
Alphabetical search
I have one question about the alphabetical search, I have written a SQL
"SELECT * FROM name where firstname like 'A%'" to show all the name which are start from A.
If I want to search from A to Z, do I need to write 26 SQL statements to do that or do I have another better methods to do that?
That mean when i click on A, it will search all the records that firstname starting from A, when i click on D, it will show all the records that the firstname is only start from D.
Anyone can help me to solve this problem.
Thx!
-
In T-SQL I would go for a stored procedure which accepts the letter as a parameter:
CREATE PROCEDURE qseNamesByLetter (
@letter char (1)
) AS
SELECT * FROM name where firstname like @letter + '%'
-
Did you try this
SELECT * FROM name where firstname like '[A-Z]%'
-
But this will give you all records where the firstname starts with any letter from A to Z, won't it?
As far as I understand the question it is about a selection based on a single letter...
-
This is just an example, I think the original poster wanted to know of any method to get list of names between a range.
-
Thanks for all guys!
skhanal, may be my previous post confuse you, I only want to click one letter, and then show the record corresponding to this letter. So I added some explanations to this new post.
andi_g69, thx for your reply, I will try later.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|