Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Inner Join by number range

Author  Topic 

Vedder
Starting Member

8 Posts

Posted - 2004-08-27 : 22:00:15
have two tables in a sql server 2000 database.

Table1
------
FromWeight (real)
ToWeight (real)
Penalty (int)

Table2
------
ID (int)
Weight (real)

What's the best way of selecting FromWeight, ToWeight and Penalty based on the Weight value of the second table?

Example Data:

FromWeight ToWeight Penalty
10 20 12
20 26 15

ID Weight
1 16
2 22
3 18

so my select would return

1 (id),16 (weight), 12 (penalty) for first entry in ID/Weight table.

Thanks in advance

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-08-27 : 22:33:01
SELECT t1.FromWeight, t1.ToWeight, t1.Penalty, t2.ID, t2.Weight
FROM Table1 t1
INNER JOIN Table2 t2 ON t2.Weight BETWEEN t1.FromWeight AND t1.ToWeight


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

Vedder
Starting Member

8 Posts

Posted - 2004-08-27 : 22:45:16
That's great. Thanks. Much appreciated.
Go to Top of Page
   

- Advertisement -