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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query help!

Status
Not open for further replies.

mkey

Programmer
Oct 3, 2001
288
CA
Hi All,

I need a query help. Let say I have two tables.
Table_A with columns (id) and (SS)

Table_B with columns (b_s) and (e_s)

I want to output the range of values for SS that falles between table_A where id=b_s and id = e_s
My script look something like this. Now I need to get the range of all values of SS.
Anythoughts on this?

select distinct a.* from table_A a inner join table_B b on
a.id = b.b_s and a.id = b.e_s
 
I am not sure if I fully understand you questions. But here is something you might want to try. I created two temp. tables and populated with some data and then created query which might be helpful for you.


===============================


create Table #table_a(id integer, ss integer )
create table #table_b(b_s integer, e_s integer)

declare @intCnt as integer
set @intcnt = 0
while @intcnt <= 17
begin
insert #table_a
select @intcnt, @intcnt + 5
set @intcnt = @intcnt + 1
end
set @intcnt = 0
while @intcnt < 10
begin
insert into #table_b(b_s, e_s)
select @intcnt, @intcnt + 5
set @intcnt = @intcnt + 1
end

select * From #table_a
select * From #table_b


--This might work for you

Select distinct #table_a.* From #table_a
inner join #table_b on #table_a.id = #table_b.b_s
inner join #table_b #b on #table_a.id = #b.e_s


=============================
 
I am confused by your description. Which column of table_A do you want to match to b_s and e_s on table_b? Your description says SS but your query shows ID.

Do the tables contain any other columns that are realted?

From your description I would propose the following solution but am not sure if it is what you need.

Select table_a.*
From Table_A, Table_B
Where ss Between b_s And e_s

Alternate:

Select a.*
From Table_A a
Join Table_B b
On a.ss Between b.b_s And b.e_s Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions in the SQL Server forum. Many of the ideas apply to all forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top