Solved

Join 2 tables using a number range

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 36
Help with SQL Query 23 39
Handle null when using linq in this line 1 20
Birthdays 3 22
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

12 Experts available now in Live!

Get 1:1 Help Now