Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select statement where i have to match several columns and a range 1

Status
Not open for further replies.

360degreehosting

IS-IT--Management
Oct 17, 2006
16
0
0
US
I need help with a select statement please that deals with combining some columns and a range


I have 2 tables that contain phone numbers:

Table1 has the following columns
AreaCode
Prefix
Suffix

Table2 has the following columns
AreaCode
Prefix
LowRangeSuffix
HighRangeSuffix

How do i write the select/join that will return all rows from Table1 that both the AreaCode and Prefix match, as well as the Suffix is between (and including) the LowRangeSuffix and HighRangeSuffix.

I do appologize I usually provide my effort up to the point i need help. But I don't even know where to start on this one.

Warmest Regards,
Steve
 
This can be done via a basic select statement.
Code:
select Table1.AreaCode, Table1.Prefix, Table1.Suffix, Table2.LowRangeSuffix, Table2.HighRangeSuffix
from table1
join table2 on table1.AreaCode = table2.AreaCode
    and Table1.Prefix = Table2.Prefix
where Table1.AreaCode = 888
     and Table1.Prefix = 555

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
No problem.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top