Solved

TSQL Question  here

Posted on 2014-10-21
2
111 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
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 …

630 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