473,382 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

SQL statement question

Howdy,

I have a table full of names, last & first, and I would like to do a SQL
select to get all of the last names that start with A-H
(I'll run another for I-P & Q-Z). The resulting last name, first name combo
needs to end up in a drop down box.

I can get the results of a query into a drop down just fine, but I can't get
the SQL statement to work right.
I've tried a few statements including LIKE, but nothing seems to work. Any
ideas on how I could go about doing this?

Thanks,
Jason
Jul 16 '05 #1
2 3020
You didn't state clearly whether the firstnames and lastnames were in the
same field together or if they were different fields. If they are in
different fields, then Leslie's suggesting will work great. If your
firstnames and lastnames are in the same field, then you need something more
like this:

Leslie's Suggestion:
SELECT * FROM table WHERE lname REGEXP "^[A-H]"

Modifed for fullname field:
SELECT * FROM table WHERE fulllname REGEXP " [A-H]"

Notice that Leslie used a '^' symbol for start of line, where I used a ' '
(space). The space idea will only work if you can assume there is exactly
one space in each field, which is a risky assumption. If the first names
and last names are combined and the number of spaces in the field are
unpredicatable, that is a real challenge. :-)

Jerry

"Jason Reljac" <jm****@hotmail.com> wrote in message
news:vh************@corp.supernews.com...
Howdy,

I have a table full of names, last & first, and I would like to do a SQL
select to get all of the last names that start with A-H
(I'll run another for I-P & Q-Z). The resulting last name, first name combo needs to end up in a drop down box.

I can get the results of a query into a drop down just fine, but I can't get the SQL statement to work right.
I've tried a few statements including LIKE, but nothing seems to work. Any ideas on how I could go about doing this?

Thanks,
Jason

Jul 16 '05 #2
JerryH wrote:
You didn't state clearly whether the firstnames and lastnames were in
the same field together or if they were different fields. If they
are in different fields, then Leslie's suggesting will work great.
If your firstnames and lastnames are in the same field, then you need
something more like this:

Leslie's Suggestion:
SELECT * FROM table WHERE lname REGEXP "^[A-H]"

Modifed for fullname field:
SELECT * FROM table WHERE fulllname REGEXP " [A-H]"

Notice that Leslie used a '^' symbol for start of line, where I used
a ' ' (space). The space idea will only work if you can assume there
is exactly one space in each field, which is a risky assumption. If
the first names and last names are combined and the number of spaces
in the field are unpredicatable, that is a real challenge. :-)

Jerry


If they are in separate fields (there is a lname field or something like
that) then both of you are nuts for using REGEXPs for such a simple
thing...just do WHERE lname BETWEEN 'aaa' AND 'hzz' etc. (Or if you are
worried about names starting with hzz, for example, hzzsomething, you can do
WHERE lname >= 'A' AND lname < 'I' (note that that's an I in quotes, not a
T...)

Using regexps is way overkill and will likely be slower.
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Greg Ofiesh | last post by:
Anyone who can help, I have two tables T1 and T2. T1 has fields K1 and F2 and T2 has fields K2 and F1. F1 is the foreign key relating to K1 and F2 is the foreign key relating to K2. My...
94
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
9
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
1
by: javedna | last post by:
Can PHP help with the following as I have tried in the MYSQL Forums and cant get any help Thanks Nabz ---------------------------------------- Hi I am developing a PHP MYSQL questionnaire...
26
by: a.mil | last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff and I encountered the following problem: When I have a for loop like this: b=b0; for (a=0,i=0;i<100;i++,b--) { if (b%i)...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
10
by: JohnO | last post by:
Hi All, This question is related to iSeries V5R4 and db2. I want to implement an AFTER DELETE trigger to save the deleted rows to an archive table, I initially defined it as a FOR EACH...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.