Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

TSQL Question  here

Posted on 2014-10-21
2
Medium Priority
?
116 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

972 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