?
Solved

help with pivoting tabular dataset and prorating quantities by month

Posted on 2014-03-14
5
Medium Priority
?
202 Views
Last Modified: 2014-03-20
I have a stored procedure that prorates quantities based on either a contract start date, contract end date, or an order requested delivery date.

A sales contract is also referred to as a "blanket" type
A regular sales order is a "standard" type

Sales Contracts use Contract Start and End date to do prorate calculation
Regular Sales Orders use the Requested Delivery Date to do prorate calculation

Right now the results are in tabular format all quantities summed up

Bu I need a way to figure out how to split the pro-ration calculation and the quantities by month.

I am including a copy of my t-sql and also a copy of some sample data I am using to test.

I hope that by looking at these files, what I am trying to accomplish becomes clearer than my description of my problem.

I hope also, someone can have the time to offer a hand on working on this, because I am clueless how to do this type of pivot, with calculation.

All the formulas are included, any question, please shoot.

Thank you much.
stored-procedure-tabular.txt
salesdemand-proratedforecast.xlsx
0
Comment
Question by:metropia
[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
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 39931766
Hi,

Without looking too long at your code, there are a couple of dates there. Which date do you want to group by?

Anyway, I find it easy to group by months using something like this:

select getdate(), dateadd( month, datediff( month, 0, getdate()), 0 )

That is, its a development of the common way to remove the time from a datetime, or in other words, group by day. This works for most things other than week and second.

HTH
  David
0
 

Author Comment

by:metropia
ID: 39931800
There is also another column I did not include at the time I uploaded the file, that is ItemNumber, I think I can group by that column.

I was not considering to group by any of the date fields, because regular sales orders use request delivery date,  and sales contracts used contract start and contract end date, and I do not understand how to group by using all these 3 cols.

Thank you
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39932252
Hi,

The bottom line for all those dates - there is ONE date which is when the transaction is realised by the accounting system. That is, if you put an order in now for delivery in a week, then often the order date is now and the accounting system shows the debt against the debtors account as of now. That is the date to use I think.

What I showed above will get grouping by month. I don't think that grouping by item number is meaningful.

HTH
  David
0
 

Author Comment

by:metropia
ID: 39933516
Hi David,

What do you mean by what you showed above? perhaps I am missing something from your post?

Thank you much.
0
 
LVL 35

Accepted Solution

by:
David Todd earned 2000 total points
ID: 39933551
Hi,

Have you run this piece of code?

select getdate(), dateadd( month, datediff( month, 0, getdate()), 0 )

Open in new window


Regards
  David
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

762 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