Solved

Join 2 tables using a number range

Posted on 2012-03-29
1
343 Views
Last Modified: 2012-03-30
HI

I have 2 SQL tables

Table 1 with a filed with an integers

Image 1
and Table 2,  with a number range e.g. 0 to 10000 and 10001 to 20000

image 2
What need to do is sum the value of the MessageCost colume in table 2 bases on tables one where the integer in the colume with the arrows falls between the number range in table 2

Thanks John
0
Comment
Question by:johngrant_ks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 12

Accepted Solution

by:
Harish Varghese earned 500 total points
ID: 37786050
This will be a plain SQL using BETWEEN operator.
Only additional consideration here is that MonthlyVolume2 (upper limit) on the last row is NULL and you need to consider this as a very high value.

SELECT SUM (T2.MessageCost)
From Table1 T1, Table2 T2
Where T1.IntColumn between T2.MonthlyVolumn1 and ISNULL(T2.MonthlyVolume2, 999999999)

Thanks,
Harish
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question