Stored Procedure issue

  • Hi,

    I have a stored procedure that is giving me an inconsistent error message.  I am using the Case statement to do different calculations based on the day of the week.  If the particular date falls on Saturday or Sunday then I need to add the overtime hours for all shifts, otherwise I calculate the total hours based on different fields (commented code).  If I simply add the three fields I get an error message:  8120 that tells me that the Overtime 1st Shift, Overtime 2nd Shift, and Overtime 3rd Shift need to be part of an aggregate function or they need to be contained in the GROUP BY clause.  But, they are contained in the GROUP BY clause and it still does not work.  If I change it so that instead of adding those three fields I Sum them then I don’t get the error message.

    Any ideas would be helpful

     CREATE PROCEDURE MTDPerformance AS

    SELECT      tblInput_Output.department,  tblInput_Output.[Date],

                          CASE [Product] WHEN 'E-Tech' THEN SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) else 0 END as 'E-TECH',

           CASE [Product] WHEN 'E-9' THEN SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) else 0 END as 'E-9',

                         CASE [Product] WHEN 'E-7' THEN SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) else 0 END as 'E-7',

                          CASE [Product] WHEN 'E-6' THEN SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) else 0 END as 'E-6',

     

           Sum([1st-output]+[2nd-output]+[3rd-output]+[OT-output]) as 'Total Output',

           [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower] as 'Manpower',

                          holidays, [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift] as 'Absent',

                          [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift] as 'Overtime',

                          [Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift] as 'Launch',

          Case Left( Datename(dw,tblAbsentOverLaunch.[Date]),1)

                When 'S' then ([Overtime 1st Shift] + [Overtime 2nd Shift]+[Overtime 3rd Shift])

      

      /*else (( [1st-output]+[2nd-output]+[3rd-output]+[OT-output]) +( [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) * 8 )

              - ( [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) +( [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])*/

            End as 'Daily Total',

          ([Overtime 1st Shift] + [Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Daily Total2'

     

    FROM          tblAbsentOverLaunch RIGHT OUTER JOIN

                           tblProduct INNER JOIN

                           tblInput_Output ON  tblProduct.department =  tblInput_Output.department AND

                           tblProduct.[Part Number] =  tblInput_Output.[Part Number] INNER JOIN

                           tblCensusDaily ON  tblInput_Output.department =  tblCensusDaily.Department AND

                           tblInput_Output.[Date] =  tblCensusDaily.[Date] LEFT OUTER JOIN

                           tblHolidaySchedule ON  tblCensusDaily.[Date] =  tblHolidaySchedule.[Date] ON

                           tblAbsentOverLaunch.[Date] =  tblCensusDaily.[Date] AND  tblAbsentOverLaunch.department =  tblCensusDaily.Department

    WHERE     ( tblInput_Output.department = N'110') AND ( tblInput_Output.[Date] >= CONVERT(DATETIME, '2004-04-01 00:00:00', 102))

    GROUP BY tblInput_Output.department, tblProduct.product, tblInput_Output.[Date],

     [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower], holidays,

     [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift],  [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift],

     [Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift], tblAbsentOverLaunch.[Date],  Datename(dw,tblAbsentOverLaunch.[Date])

    GO

     

  • Well Try This if it works

    CREATE PROCEDURE MTDPerformance AS

    SELECT  tblInput_Output.department, 

     tblInput_Output.[Date],

            CASE [Product]

     WHEN 'E-Tech'

     THEN

      SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output])

     else

      0

     END as 'E-TECH',

            CASE [Product]

     WHEN 'E-9'

     THEN

      SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output])

     else

      0

     END as 'E-9',

            CASE [Product]

     WHEN 'E-7'

     THEN

      SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output])

     else

      0

     END as 'E-7',

            CASE [Product]

     WHEN 'E-6'

     THEN

      SUM([1st-output] + [2nd-output] + [3rd-output] + [OT-output])

     else

      0 END as 'E-6',

            Sum([1st-output]+[2nd-output]+[3rd-output]+[OT-output]) as 'Total Output',

            [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower] as 'Manpower',

            holidays, [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift] as 'Absent',

            [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift] as 'Overtime',

            [Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift] as 'Launch',

           Case Left( Datename(dw,tblAbsentOverLaunch.[Date]),1)

            When 'S'

     then

      ([Overtime 1st Shift] + [Overtime 2nd Shift]+[Overtime 3rd Shift])

     

       else

      (( [1st-output]+[2nd-output]+[3rd-output]+[OT-output]) +( [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) * 8 )

              - ( [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) +( [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

            End as 'Daily Total',

     ([Overtime 1st Shift] + [Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Daily Total2'

    FROM    tblAbsentOverLaunch

    RIGHT OUTER JOIN

            tblProduct

    INNER JOIN

     tblInput_Output ON  tblProduct.department =  tblInput_Output.department

    AND

     tblProduct.[Part Number] =  tblInput_Output.[Part Number]

    INNER JOIN

            tblCensusDaily ON  tblInput_Output.department =  tblCensusDaily.Department

    AND

     tblInput_Output.[Date] =  tblCensusDaily.[Date]

    LEFT OUTER JOIN

            tblHolidaySchedule ON  tblCensusDaily.[Date] =  tblHolidaySchedule.[Date]

    ON

     tblAbsentOverLaunch.[Date] =  tblCensusDaily.[Date]

    AND 

     tblAbsentOverLaunch.department =  tblCensusDaily.Department

    WHERE    

     ( tblInput_Output.department = N'110') AND ( tblInput_Output.[Date] >= CONVERT(DATETIME, '2004-04-01 00:00:00', 102))

    GROUP BY

     tblInput_Output.department,

     tblProduct.product,

     tblInput_Output.[Date],

      [1st Shift Manpower],

     [2nd Shift Manpower],

     [3rd Shift Manpower]

     holidays,

      [Absent 1st Shift],

     [Absent 2nd Shift],

     [Absent 3rd Shift], 

     [Overtime 1st Shift],

     [Overtime 2nd Shift],

     [Overtime 3rd Shift],

      [Launch 1st Shift],

     [Launch 2nd Shift],

     [Launch 3rd Shift],

     tblAbsentOverLaunch.[Date], 

     tblAbsentOverLaunch.[Date]

    GO

     

    Prasad Bhogadi
    www.inforaise.com

  • Hi Prasad Bhogadi,

    Thank you for the fast reply but unfortunately it still did not work. This is the message I am getting:

    Thank you

  • I rewrote the query like this

    SELECT department,

      [Date],

      SUM(CASE [Product] WHEN 'E-Tech' THEN [output] else 0 END) as 'E-TECH',

      SUM(CASE [Product] WHEN 'E-9' THEN THEN [output] else 0 END) as 'E-9',

      SUM(CASE [Product] WHEN 'E-7' THEN THEN [output] else 0 END) as 'E-7',

      SUM(CASE [Product] WHEN 'E-6' THEN THEN [output] else 0 END) as 'E-6',

      SUM([output]) as 'Total Output',

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total],

      [Daily Total2]

    FROM (SELECT tblInput_Output.department,

            tblInput_Output.[Date],

            ([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) as 'Output',

            ([1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) as 'Manpower',

            holidays,

            ([Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) as 'Absent',

            ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Overtime',

            ([Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift]) as 'Launch',

            Case Left( Datename(dw,tblAbsentOverLaunch.[Date]),1)

              When 'S' then ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

              else (( [1st-output]+[2nd-output]+[3rd-output]+[OT-output]) +( [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) * 8 )

                     - ( [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) +( [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])*/

              End as 'Daily Total',

            ([Overtime 1st Shift] + [Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Daily Total2'

            FROM tblAbsentOverLaunch

              RIGHT OUTER JOIN tblProduct

              INNER JOIN tblInput_Output

                ON tblProduct.department =  tblInput_Output.department

                AND tblProduct.[Part Number] =  tblInput_Output.[Part Number]

              INNER JOIN tblCensusDaily

                ON tblInput_Output.department =  tblCensusDaily.Department

                AND tblInput_Output.[Date] =  tblCensusDaily.[Date]

              LEFT OUTER JOIN tblHolidaySchedule

                ON  tblCensusDaily.[Date] =  tblHolidaySchedule.[Date]

              ON tblAbsentOverLaunch.[Date] =  tblCensusDaily.[Date]

              AND tblAbsentOverLaunch.department =  tblCensusDaily.Department

            WHERE ( tblInput_Output.department = N'110')

            AND ( tblInput_Output.[Date] >= CONVERT(DATETIME, '2004-04-01 00:00:00', 102))

          ) a

    GROUP BY

      department,

      product,

      [Date],

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total],

      [Daily Total2]

    cannot validate it as i do not have tables but i am concerned with the login in the table joins

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Hi Dragon,

    I could not see the error that you pasted, basically I missed a comma before holidays column in the group by clause, if you could please re post the error that you are getting, I would see what I missed.

    Prasad Bhogadi
    www.inforaise.com

  • Hi Prasad,

    I fixed the comma before holidays but the error was the same as before.  My overtime fields need to be part of an aggregate function or contained in the GROUP BY clause.

    Thank you

  • If you use a GROUP BY clause then any column not part of an aggregate statement needs to be specified in the GROUP BY as per the error message. Either specify each column individually (which may upset your sum or output) or specify each calculation separately in the GROUP BY. To add your commented code you will have to specify each column individually, or the WHOLE calculation, in the GROUP BY.

    My reworking does all the calculation in the subquery therefore making the GROUPING simpler.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Hi David,

    I like what you did with the query.  It looks much "cleaner" than before. However, I get the following message: Line 59 (highlighted): Incorrect syntax near 'Daily Total'

    Thank you.

    CREATE PROCEDURE MTDPerformance3

    AS

    SELECT department,

      [Date],

      SUM(CASE [Product] WHEN 'E-Tech' THEN [output] else 0 END) as 'E-TECH',

      SUM(CASE [Product] WHEN 'E-9' THEN  [output] else 0 END) as 'E-9',

      SUM(CASE [Product] WHEN 'E-7' THEN  [output] else 0 END) as 'E-7',

      SUM(CASE [Product] WHEN 'E-6' THEN  [output] else 0 END) as 'E-6',

      SUM([output]) as 'Total Output',

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total]

    FROM (SELECT tblInput_Output.department,

            tblInput_Output.[Date],

            ([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) as  'Output',

            ([1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) as 'Manpower',

            holidays,

            ([Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) as 'Absent',

            ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Overtime',

            ([Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift]) as 'Launch',

           

             Case Left( Datename(dw,tblAbsentOverLaunch.[Date]),1)

              When 'S' then ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

     else (( [1st-output]+[2nd-output]+[3rd-output]+[OT-output]) +( [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) * 8 ) -

      ([Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) +( [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

              End as 'Daily Total'

     

            FROM tblAbsentOverLaunch

              RIGHT OUTER JOIN tblProduct

              INNER JOIN tblInput_Output

                ON tblProduct.department =  tblInput_Output.department

                AND tblProduct.[Part Number] =  tblInput_Output.[Part Number]

              INNER JOIN tblCensusDaily

                ON tblInput_Output.department =  tblCensusDaily.Department

                AND tblInput_Output.[Date] =  tblCensusDaily.[Date]

              LEFT OUTER JOIN tblHolidaySchedule

                ON  tblCensusDaily.[Date] =  tblHolidaySchedule.[Date]

              ON tblAbsentOverLaunch.[Date] =  tblCensusDaily.[Date]

              AND tblAbsentOverLaunch.department =  tblCensusDaily.Department

            WHERE ( tblInput_Output.department = N'110')

            AND ( tblInput_Output.[Date] >= CONVERT(DATETIME, '2004-04-01 00:00:00', 102))

         

    GROUP BY

      department,

      [product],

      [Date],

      [Manpower],

      holidays,

      [Absent],

      [Overtime],

      [Launch],

      [Daily Total]

    GO

  • the

    ) a

    seems to be missing from your post.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • I added the )a and now I am getting the following message: Incorrect syntax near the keyword 'THEN', Incorrect syntax near 'a'. By the way what is 'a' used for anyways. I am new to stored procedures.

    Thank you

    CREATE PROCEDURE MTDPerformance3

    AS

    SELECT department,

      [Date],

      SUM(CASE [Product] WHEN 'E-Tech' THEN [output] else 0 END) as 'E-TECH',

      SUM(CASE [Product] WHEN 'E-9' THEN THEN [output] else 0 END) as 'E-9',

      SUM(CASE [Product] WHEN 'E-7' THEN THEN [output] else 0 END) as 'E-7',

      SUM(CASE [Product] WHEN 'E-6' THEN THEN [output] else 0 END) as 'E-6',

      SUM([output]) as 'Total Output',

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total]

    FROM (SELECT tblInput_Output.department,

            tblInput_Output.[Date],

            ([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) as 'Output',

            ([1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) as 'Manpower',

            holidays,

            ([Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) as 'Absent',

            ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Overtime',

            ([Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift]) as 'Launch',

            Case Left( Datename(dw,tblAbsentOverLaunch.[Date]),1)

              When 'S' then ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

             else (( [1st-output]+[2nd-output]+[3rd-output]+[OT-output]) +( [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) * 8 )

                     - ( [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) +( [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

              End as 'Daily Total'

            FROM tblAbsentOverLaunch

              RIGHT OUTER JOIN tblProduct

              INNER JOIN tblInput_Output

                ON tblProduct.department =  tblInput_Output.department

                AND tblProduct.[Part Number] =  tblInput_Output.[Part Number]

              INNER JOIN tblCensusDaily

                ON tblInput_Output.department =  tblCensusDaily.Department

                AND tblInput_Output.[Date] =  tblCensusDaily.[Date]

              LEFT OUTER JOIN tblHolidaySchedule

                ON  tblCensusDaily.[Date] =  tblHolidaySchedule.[Date]

              ON tblAbsentOverLaunch.[Date] =  tblCensusDaily.[Date]

              AND tblAbsentOverLaunch.department =  tblCensusDaily.Department

            WHERE ( tblInput_Output.department = N'110')

            AND ( tblInput_Output.[Date] >= CONVERT(DATETIME, '2004-04-01 00:00:00', 102))

          ) a

    GROUP BY

      department,

      product,

      [Date],

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total]

     

  • Try this

    SELECT department,

      [Date],

      SUM(CASE [Product] WHEN 'E-Tech' THEN [output] else 0 END) as 'E-TECH',

      SUM(CASE [Product] WHEN 'E-9' THEN [output] else 0 END) as 'E-9',

      SUM(CASE [Product] WHEN 'E-7' THEN [output] else 0 END) as 'E-7',

      SUM(CASE [Product] WHEN 'E-6' THEN [output] else 0 END) as 'E-6',

      SUM([output]) as 'Total Output',

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total]

    FROM (SELECT tblInput_Output.department,

            tblInput_Output.[Date],

     product,

            ([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) as 'Output',

            ([1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) as 'Manpower',

            holidays,

            ([Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) as 'Absent',

            ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Overtime',

            ([Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift]) as 'Launch',

            Case Left( Datename(dw,tblAbsentOverLaunch.[Date]),1)

              When 'S' then ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

             else (( [1st-output]+[2nd-output]+[3rd-output]+[OT-output]) +( [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) * 8 )

                     - ( [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) +( [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

              End as 'Daily Total'

            FROM tblAbsentOverLaunch

              RIGHT OUTER JOIN tblProduct

              INNER JOIN tblInput_Output

                ON tblProduct.department =  tblInput_Output.department

                AND tblProduct.[Part Number] =  tblInput_Output.[Part Number]

              INNER JOIN tblCensusDaily

                ON tblInput_Output.department =  tblCensusDaily.Department

                AND tblInput_Output.[Date] =  tblCensusDaily.[Date]

              LEFT OUTER JOIN tblHolidaySchedule

                ON  tblCensusDaily.[Date] =  tblHolidaySchedule.[Date]

              ON tblAbsentOverLaunch.[Date] =  tblCensusDaily.[Date]

              AND tblAbsentOverLaunch.department =  tblCensusDaily.Department

            WHERE ( tblInput_Output.department = N'110')

            AND ( tblInput_Output.[Date] >= CONVERT(DATETIME, '2004-04-01 00:00:00', 102))

          ) a

    GROUP BY

      department,

      [Date],

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total]

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Hi David,

    It worked. I have to check the output next but so far so good.

    Thank you very much for your replies, I would not be able to figure it out on my own.  What was the difference from your previous post? I am trying to understand what you did.

     

  • There was errors in the case statements and i missed product in the select. When using subqueries you have to give them an alias, i called the subquery a but you could it any valid sql name. You can reference the contents of the subquery using the alias including in joins.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • This gets compiled, this is exactly what David Posted but I just removed the THEN KEYWORD which was duplicated.

    CREATE PROCEDURE MTDPerformance3

    AS

    SELECT department,

      [Date],

      SUM(CASE [Product] WHEN 'E-Tech' THEN [output] else 0 END) as 'E-TECH',

      SUM(CASE [Product] WHEN 'E-9' THEN  [output] else 0 END) as 'E-9',

      SUM(CASE [Product] WHEN 'E-7' THEN  [output] else 0 END) as 'E-7',

      SUM(CASE [Product] WHEN 'E-6' THEN  [output] else 0 END) as 'E-6',

      SUM([output]) as 'Total Output',

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total]

    FROM (SELECT tblInput_Output.department,

            tblInput_Output.[Date],

            ([1st-output] + [2nd-output] + [3rd-output] + [OT-output]) as 'Output',

            ([1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) as 'Manpower',

            holidays,

            ([Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) as 'Absent',

            ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift]) as 'Overtime',

            ([Launch 1st Shift]+[Launch 2nd Shift]+[Launch 3rd Shift]) as 'Launch',

            Case Left( Datename(dw,tblAbsentOverLaunch.[Date]),1)

              When 'S' then ([Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

             else (( [1st-output]+[2nd-output]+[3rd-output]+[OT-output]) +( [1st Shift Manpower]+[2nd Shift Manpower]+[3rd Shift Manpower]) * 8 )

                     - ( [Absent 1st Shift]+[Absent 2nd Shift]+[Absent 3rd Shift]) +( [Overtime 1st Shift]+[Overtime 2nd Shift]+[Overtime 3rd Shift])

              End as 'Daily Total'

            FROM tblAbsentOverLaunch

              RIGHT OUTER JOIN tblProduct

              INNER JOIN tblInput_Output

                ON tblProduct.department =  tblInput_Output.department

                AND tblProduct.[Part Number] =  tblInput_Output.[Part Number]

              INNER JOIN tblCensusDaily

                ON tblInput_Output.department =  tblCensusDaily.Department

                AND tblInput_Output.[Date] =  tblCensusDaily.[Date]

              LEFT OUTER JOIN tblHolidaySchedule

                ON  tblCensusDaily.[Date] =  tblHolidaySchedule.[Date]

              ON tblAbsentOverLaunch.[Date] =  tblCensusDaily.[Date]

              AND tblAbsentOverLaunch.department =  tblCensusDaily.Department

            WHERE ( tblInput_Output.department = N'110')

            AND ( tblInput_Output.[Date] >= CONVERT(DATETIME, '2004-04-01 00:00:00', 102) )) a

    GROUP BY

      department,

      product,

      [Date],

      Manpower,

      holidays,

      Absent,

      Overtime,

      Launch,

      [Daily Total]

     Thanks

    -Prasad

    Prasad Bhogadi
    www.inforaise.com

  • Hi,

    I ran the stored procedure and got the following output.  Everything is working fine except that my data is not being grouped by date.  As you can see I am getting three different records for some days.  I think that the reason I am getting this output is becuase my last column (Daily Total) is different on different days and that is why it is not being grouped. I need it to sum my [product] numbers (in red) and output one value for that day and then calculate the last column.

    Any suggestions will be helpful.

    110 2004-04-01 00:00:00 0.0 0.0 0.0 0.0 0.0 53.0 0 32.0 84 54 476.0

    110 2004-04-01 00:00:00 47.0 0.0 0.0 0.0 47.0 53.0 0 32.0 84 54 523.0

    110 2004-04-01 00:00:00 99.0 0.0 0.0 0.0 99.0 53.0 0 32.0 84 54 575.0

    110 2004-04-02 00:00:00 16.0 0.0 0.0 0.0 16.0 53.0 1 75.0 48 30 413.0

    110 2004-04-02 00:00:00 25.0 0.0 0.0 0.0 25.0 53.0 1 75.0 48 30 422.0

    110 2004-04-03 00:00:00 60.0 0.0 0.0 0.0 60.0 53.0 0 0.0 208 24 208.0

    110 2004-04-04 00:00:00 54.0 0.0 0.0 0.0 54.0 53.0 0 0.0 342 36 342.0

    110 2004-04-05 00:00:00 34.0 0.0 0.0 0.0 34.0 53.0 0 56.0 100 60 502.0

    110 2004-04-05 00:00:00 73.0 0.0 0.0 0.0 73.0 53.0 0 56.0 100 60 541.0

    110 2004-04-06 00:00:00 29.0 0.0 0.0 0.0 29.0 53.0 0 36.0 78 44 495.0

    110 2004-04-06 00:00:00 100.0 0.0 0.0 0.0 100.0 53.0 0 36.0 78 44 566.0

    110 2004-04-07 00:00:00 17.0 0.0 0.0 0.0 17.0 53.0 0 48.0 86 76 479.0

    110 2004-04-07 00:00:00 36.0 0.0 0.0 0.0 36.0 53.0 0 48.0 86 76 498.0

    110 2004-04-08 00:00:00 0.0 0.0 0.0 0.0 0.0 53.0 0 44.0 70 46 450.0

Viewing 15 posts - 1 through 15 (of 18 total)

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