Solved

Join 2 tables using a number range

Posted on 2012-03-29
1
336 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
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now