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
 General SQL Server Forums
 New to SQL Server Programming
 Link tables on a "Between a AND b" where clause

Author  Topic 

ErwinB
Starting Member

2 Posts

Posted - 2009-08-22 : 16:54:31
Hi,

I've been messing around for a while now, but my SQL skills are more rusty than I thought and Google-searches didn't help me any further, so I hope some SQL guru can help me.

The (simplified) situation:

Table A with fields Name, Score
Table B with fields ScoreRangeLow, ScoreRangeHigh, ScoreDescription

I want to create a select statement that displays Name, Score, ScoreDescription
where the latter comes from the record in table B where the Score is between the ScoreRangeLow and ScoreRangeHigh.

Example:

Table A has a record "Jim, 75"
Table B has a record "60, 80, Pretty Good"

So the result should be "Jim, 75, Pretty Good".


Your help is much appreciated.

Erwin

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2009-08-23 : 02:09:23
select name,score, scoredescription
from tableA a inner join tableb b on a.score between ScoreRangeLow and ScoreRangeHigh

if that doesn't work change between to >= and <=
Go to Top of Page

ErwinB
Starting Member

2 Posts

Posted - 2009-08-23 : 11:59:50
Thanks LoztInSpace !

Turns out I was close, but missed the table alias. Your SQL statement works like charm.
Go to Top of Page
   

- Advertisement -