May or may not have to use the pivot table for weekly compare data ?

  • HI All.....

    I have a table" ProdSchedule

    Model Date upload Lot_qty Prod_Date

    AAA 2010-05-14 1500 2010-05-15

    AAA 2010-05-14 2500 2010-06-18

    AAA 2010-05-21 3500 2010-06-01

    AAA 2010-05-21 4500 2010-05-25

    BBB 2010-05-14 5500 2010-05-05

    BBB 2010-05-21 6500 2010-06-04

    In this case, i need to compare the lot_qty on period month(get from prod_date)

    at every week (this week and last week).

    And I need the output like this format:

    Model Date upload May June

    AAA 2010-05-21 4500 3500

    AAA 2010-05-14 1500 2500

    DiffA 3000 1000

    BBB 2010-05-21 5500 0

    BBB 2010-05-14 0 6500

    DiffB -5500 6500

    may question is may or may not have to use the pivot table?

    Please suggest with your experience which is suitable for me.

    Thank You......

  • Check out the two links in my signature for dealing with CROSS-TABS and PIVOTS - this looks like what you'll need.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Hi ... thank you for your share that's link.

    previously I've read, even practicing.

    And follows the results of the data:

    Model Dateupload May June

    AAA 2010-05-21 4500 3500

    AAA 2010-05-14 1500 2500

    BBB 2010-05-21 5500 0

    BBB 2010-05-14 0 6500

    What I'm confused, how can I compare the data in each model (which is controlled by fields dateupload), because I want to display a REPORT like this:

    Model Dateupload May June

    AAA 2010-05-21 4500 3500

    AAA 2010-05-14 1500 2500

    DiffAAA 3000 1000

    BBB 2010-05-21 5500 0

    BBB 2010-05-14 0 6500

    DiffBBB -5500 6500

    Is the process of compare data when I build the REPORT? or may or may not have to use the pivot table?

    Thank You,

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply