Solved

TSQL Question  here

Posted on 2014-10-21
2
102 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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 …
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

786 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