Solved

TSQL Question  here

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

757 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

22 Experts available now in Live!

Get 1:1 Help Now