Solved

Join 2 tables using a number range

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

785 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