Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 8914

SQL Pivot Query

$
0
0

Hi Experts

 

I recently purchased a copy of Gordon's book to help me create a pivot query based on the examples at the end which I hope to show me a set of data based on my Sales Order tables.   Unfortunately I have found it a little too complex.

 

In my ORDR table I have 10 UDFs which relate to various statuses and dates in the sales order process. 

 

What I would like is to see a pivot table query of the sum quanties of items at the different stages (as rows) against the dates in weeks.

 

In the rows would be the status UDF fields:

 

U_DES_STAGE

U_PRN_STAGE

U_PRS_STAGE

U_SEW_STAGE

U_EMB_STAGE

 

for each UDF there is an associated date UDF

 

U_DES_STAGE_DATE

U_PRN_STAGE_DATE

U_PRS_STAGE_DATE

U_SEW_STAGE_DATE

U_EMB_STAGE_DATE

 

 

The columns I require in the pivot table would be the UDF stage dates which are always input for the week ending Friday.

 

The data in the pivot should be the sum of the quantities in the sales orders rows RDR1.

 

StageW/E 14/3/2014W/E 21/3/2014W/E 28/3/2014W/E 4/4/2014W/E 11/4/2014W/E 18/4/2014
DESSum of QtySum of QtySum of QtySum of QtySum of QtySum of Qty
PRNSum of QtySum of QtySum of QtySum of QtySum of QtySum of Qty
PRSSum of QtySum of QtySum of QtySum of QtySum of QtySum of Qty
SEWSum of QtySum of QtySum of QtySum of QtySum of QtySum of Qty
EMBSum of QtySum of QtySum of QtySum of QtySum of QtySum of Qty

 

 

The problem is that I am not sure as to how to add the WHERE clause to limit the results to only the 5 items (DES% or PRN% or PRS% or SEW% or EMB%)

 

I would be very grateful for any assistance.

 

Regards

Geoff


Viewing all articles
Browse latest Browse all 8914

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>