?
Solved

Join 2 tables using a number range

Posted on 2012-03-29
1
Medium Priority
?
346 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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 fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 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