Solved

TSQL Question  here

Posted on 2014-10-21
2
101 Views
Last Modified: 2014-10-21
Hello Gurus,

Please see attached  

There are two tables –
Metric_DTrange that specifies for a given combination of product and saleClass – the a code (AGMT) and gives its metric VolW. Then there is a blank column “metric_sum” within it as well

Daily_m – is a table that lists a given combination of product + salesClass + daily date ad lists out the metric for that date.

What is needed – I need tp update column “Metric_sum” of table metric_DTRange is such a way  - when I read for a given combination of product and salesClass in that table – I see the start and end dates. Then I go to the daily_m table to grab the [Metric] that lies within that date range  for the same combination of product + salesClass.
For example:
AGMT      Product      salesClass      st_date      end_date      VolW      Metric_sum
TRN01      P1      A      3/1/2014      3/10/2014      14-Feb      46
Where the metric sum comes to 46 – it sums all te metric between the dates of 3/1 and 3/10 within the daily_m table and puts it in the metric_DTrange
Book3.xlsx
0
Comment
Question by:Rayne
2 Comments
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 500 total points
ID: 40395853
Here is the code :

update   t set t.Metric_sum=(select sum(m.metric) from  Daily_m m where m.product=t.product and m.date between t.st_date and t.end_date) 
from Metric_DTrange  t

Open in new window

0
 

Author Comment

by:Rayne
ID: 40396035
thank you samo4Fun :)
thank you
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

911 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

24 Experts available now in Live!

Get 1:1 Help Now