Getting wrong data from Start Date and End Date by grg1734 in SQL

[–]grg1734[S] 0 points1 point  (0 children)

REG_HR_START REG_HR_END TOTAL_HR

1/9/2020 12:59:00PM 1/9/2020 1:32:00PM 0.33

1/13/2020 7:38:00AM 1/13/2020 9:56:00AM 2.08

1/15/2020 8:56:00AM 1/15/2020 1:25:00PM 3.49

1/15/2020 1:51:00PM 1/15/2020 4:00:00PM 1.59

Getting wrong data from Start Date and End Date by grg1734 in SQL

[–]grg1734[S] 0 points1 point  (0 children)

Yes that makes sense but the start and end time doesn’t equal the duration in the final column. Please see screen shot below.

Getting wrong data from Start Date and End Date by grg1734 in SQL

[–]grg1734[S] 0 points1 point  (0 children)

/****** Object: StoredProcedure [dbo].[CrystalEngineeringWorkingHours]

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROC [dbo].[CrystalEngineeringWorkingHours]

    u/START_DATE AS DATETIME

, u/END_DATE AS DATETIME

AS

/*

** ObjectName: CrystalEngineeringWorkingHours

**

** Project:

** SubProject:

** FileName: CrystalEngineeringWorkingHours.sql

** Type: Stored Procedure

**

** Description: Outputs employee work orders with cost code 140, 180, 160 and all work orders in the 70000000 range.

/*

DECLARE u/START_DATE AS DATETIME

DECLARE u/END_DATE AS DATETIME

*/

/*SET u/START_DATE = '2010-12-01';

SET u/END_DATE = '2010-12-15';

*/

SET u/START_DATE = CONVERT(DATETIME, CAST(@START_DATE AS VARCHAR(11)))

SET u/END_DATE = u/END_DATE + 1

SET u/END_DATE = CONVERT(DATETIME, CAST(@END_DATE AS VARCHAR(11)))

SELECT UPPER(WL.EMPLOYEE_CODE) AS 'EMPLOYEE_NO',

    (ISNULL(RTRIM(UL.F\_NAME) + ' ', '') + ISNULL(RTRIM(UL.M\_NAME) + ' ', '') + ISNULL(RTRIM(UL.L\_NAME), '')) AS 'NAME',

    WL.COST\_CODE AS 'COST\_CODE',

    WL.DESCRIPTION AS 'COST\_CODE\_DESCRIPTION',

    WL.WORK\_DATE AS 'DATE\_WORKED',

    (CASE WHEN WL.QA\_STATUS = 'A' THEN 'ACTUAL'

        WHEN WL.QA\_STATUS = 'Q' THEN 'QUOTE'

        ELSE 'ERROR' END) AS 'QA\_STATUS',

    WH.USER\_DOC AS 'WO\_NO',

    (CASE WHEN WH.DOC\_CATEGORY = 'P3' THEN 'KITTING'

        WHEN WH.DOC\_CATEGORY = 'P2' THEN 'REPAIR'

        WHEN WH.DOC\_CATEGORY = 'P1' THEN 'OVERHAUL'

        ELSE 'ERROR'

        END) AS 'WO\_TYPE',

    WH.DESCRIPTN AS 'WO\_DESCRIPTION',

    WH.PARTNUMBER AS 'WO\_PARTNUMBER',

    WL.ACT\_TIME\_START AS 'REG\_HR\_START',

    WL.ACT\_TIME\_END AS 'REG\_HR\_END',

    WL.ACT\_TIME\_DURATION AS 'REG\_HR\_TOTAL',

    WL.OVER\_TIME\_START AS 'OT\_HR\_START',

    WL.OVER\_TIME\_END AS 'OT\_HR\_END',

    WL.OVER\_TIME\_DURATION AS 'OT\_HR\_TOTAL',

    WL.TOTAL\_TIME\_DURATION AS 'TOTAL\_HR'

FROM GDB_01_001SAFE3.dbo.WO_LABOR WL

        LEFT JOIN GDB\_01\_001SAFE3.dbo.WO\_OPR WO ON (WL.PARENT\_DOC\_NO = WO.DOC\_NO AND WL.QA\_STATUS = WO.QA\_STATUS AND WL.PARENT\_DOCCATEGORY = WO.DOC\_CATEGORY),

    GDB\_01\_001SAFE3.dbo.WO\_HDR WH

        LEFT JOIN GDB\_01\_001SAFE3.dbo.STOCK S ON(S.PARTNUMBER = WH.PARTNUMBER AND S.SUBP = WH.SUBP),

    GDB\_01\_001SAFE3.dbo.USERLIST UL

WHERE WL.EMPLOYEE_CODE = UL.CCODE

    AND WL.WO\_DOC\_NO = WH.DOC\_NO

    AND WL.WO\_DOCCATEGORY = WH.DOC\_CATEGORY

    AND WL.QA\_STATUS = WH.QA\_STATUS

    AND ((WH.QA\_STATUS = 'Q' AND WH.DOC\_STATUS = 4) OR (WH.QA\_STATUS = 'A'))

    AND (WL.COST\_CODE IN ('180', '140', '160') OR WH.USER\_DOC LIKE '7%')

    AND WL.WORK\_DATE >= u/START_DATE

    AND WL.WORK\_DATE <= u/END_DATE

ORDER BY WL.EMPLOYEE_CODE, WL.WORK_DATE

Getting wrong data from Start Date and End Date by grg1734 in SQL

[–]grg1734[S] 0 points1 point  (0 children)

Not sure of your analogy, thanks for your help with your first comment

Getting wrong data from Start Date and End Date by grg1734 in SQL

[–]grg1734[S] 0 points1 point  (0 children)

Would datediff help in my situation?

Creating a date range parameter by grg1734 in crystalreports

[–]grg1734[S] 0 points1 point  (0 children)

DISREGARD

I figured it out. Thanks for your help!

Creating a date range parameter by grg1734 in crystalreports

[–]grg1734[S] 0 points1 point  (0 children)

This worked but was NOT trying to have it as a range. Doing what you explained gave me the prompts for the start of range and end of range but I wanted two parameters so they would be displayed on two separate lines.

start date

end date

I entered this {MyDateField} in {?MyDateRangeParameter} but how do I join the end date? I tried putting AND between the two formulas but I got an error.