Week wise query in Sqlserver

  • Hi,

    I have a table with below format.

    PartMachineQtyStart DateEnd Date

    Part 1Machine 1465011/03/2014 06:55:0011/05/2014 12:55:00

    Part2Machine 1560011/05/2014 14:00:0011/07/2014 06:00:00

    Part 3Machine 1297511/07/2014 06:00:0011/09/2014 06:00:00

    Part 4Machine 1275011/03/2014 06:05:0011/05/2014 06:00:00

    Part 5Machine 1100011/05/2014 06:00:0011/06/2014 06:00:00

    Part 6Machine 1130011/06/2014 06:00:0011/07/2014 06:00:00

    Part 7Machine 1135011/09/2014 06:00:0011/10/2014 06:00:00

    Part 8Machine2162511/03/2014 06:00:0011/05/2014 06:00:00

    Part 9Machine2412511/05/2014 06:00:0011/09/2014 06:00:00

    Part 10Machine280011/09/2014 06:00:0011/10/2014 06:00:00

    Part 11Machine3495011/03/2014 06:00:0011/04/2014 14:20:00

    Part 12Machine350011/04/2014 14:20:0011/05/2014 14:20:00

    Part 13Machine3665011/05/2014 15:00:0011/07/2014 06:00:00

    Part 14Machine330011/07/2014 06:30:0011/08/2014 06:00:00

    Part 15Machine3765011/08/2014 06:30:0011/10/2014 06:00:00

    based on the above data i want to generate a report as

    MACHINEDATE

    3456789

    Machine 1Part APart A / Part BPart BPart CNO PLAN

    TOTAL SHOTS PLAN160033001100 / 2000360014001575

    Machine 2Part DPart EPart FPart GPart G / Part FPart H

    TOTAL SHOTS ACTUAL11001650100013001000 * 2 350 *2 / 9001350

    Machine 3Part IPart JPark K

    TOTAL SHOTS PLAN5001125750112511251125800

  • Raghunathan (11/17/2014)


    based on the above data i want to generate a report as

    MACHINEDATE

    3456789

    Machine 1Part APart A / Part BPart BPart CNO PLAN

    TOTAL SHOTS PLAN160033001100 / 2000360014001575

    Machine 2Part DPart EPart FPart GPart G / Part FPart H

    TOTAL SHOTS ACTUAL11001650100013001000 * 2 350 *2 / 9001350

    Machine 3Part IPart JPark K

    TOTAL SHOTS PLAN5001125750112511251125800

    Quick question, can you elaborate on what/how you want to get these results?

    😎

    BTW here is the dataset in a consumable format

    USE tempdb;

    GO

    SET NOCOUNT ON;

    IF OBJECT_ID('dbo.TBL_MACHINE_DATA') IS NOT NULL DROP TABLE dbo.TBL_MACHINE_DATA;

    CREATE TABLE dbo.TBL_MACHINE_DATA

    (

    Part VARCHAR(25) NOT NULL

    ,Machine VARCHAR(25) NOT NULL

    ,Qty INT NOT NULL

    ,[Start Date] DATETIME NOT NULL

    ,[End Date] DATETIME NOT NULL

    );

    INSERT INTO dbo.TBL_MACHINE_DATA (Part,Machine,Qty,[Start Date],[End Date])

    VALUES

    ('Part 1', 'Machine 1',4650,'11/03/2014 06:55:00','11/05/2014 12:55:00')

    ,('Part 2', 'Machine 1',5600,'11/05/2014 14:00:00','11/07/2014 06:00:00')

    ,('Part 3', 'Machine 1',2975,'11/07/2014 06:00:00','11/09/2014 06:00:00')

    ,('Part 4', 'Machine 1',2750,'11/03/2014 06:05:00','11/05/2014 06:00:00')

    ,('Part 5', 'Machine 1',1000,'11/05/2014 06:00:00','11/06/2014 06:00:00')

    ,('Part 6', 'Machine 1',1300,'11/06/2014 06:00:00','11/07/2014 06:00:00')

    ,('Part 7', 'Machine 1',1350,'11/09/2014 06:00:00','11/10/2014 06:00:00')

    ,('Part 8', 'Machine 2',1625,'11/03/2014 06:00:00','11/05/2014 06:00:00')

    ,('Part 9', 'Machine 2',4125,'11/05/2014 06:00:00','11/09/2014 06:00:00')

    ,('Part 10','Machine 2', 800,'11/09/2014 06:00:00','11/10/2014 06:00:00')

    ,('Part 11','Machine 3',4950,'11/03/2014 06:00:00','11/04/2014 14:20:00')

    ,('Part 12','Machine 3', 500,'11/04/2014 14:20:00','11/05/2014 14:20:00')

    ,('Part 13','Machine 3',6650,'11/05/2014 15:00:00','11/07/2014 06:00:00')

    ,('Part 14','Machine 3', 300,'11/07/2014 06:30:00','11/08/2014 06:00:00')

    ,('Part 15','Machine 3',7650,'11/08/2014 06:30:00','11/10/2014 06:00:00');

    SELECT

    MD.Part

    ,MD.Machine

    ,MD.Qty

    ,MD.[Start Date]

    ,MD.[End Date]

    FROM dbo.TBL_MACHINE_DATA MD;

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

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