• jerome.morris (11/15/2012)


    SELECT MachineName, ModeName, FileName, UserName, StartDate, StartTime, EndDate, EndTime, RunTime, DelayTime, MachineStopTime, OperatorStopTime,

    MachineFaultTime, OperatorFaultTime, NumMachineStops, NumOperatorStops, NumDelays, Feeder00Count, InputFeederCount, AvgChassisSpeed,

    TotalPcsOutsorted, TotalPcsOutsortedGood, TotalPcsOutsortedMaybe, TotalPcsOutsortedBad, TotalPcsOutsortedUnk, FilledCycles, EmptyCycles, PiecesFed,

    PiecesCompleted, Id

    FROM ProdDataTB

    WHERE (DATEPART(yyyy, @date1) = DATEPART(yyyy, EndDate)) AND (DATEPART(mm, @date1) = DATEPART(mm, EndDate))

    What am I doing wrong I only want to return the year and month that match

    10/10/2012 so all end dates in oct for the year 2012

    Without converting! the EndDate is datetime column

    Thanks

    J

    I don't see that you are doing anything wrong at least logically. You have however put together a nonSARGable where clause. How about this instead?

    Where EndDate > dateadd(mm, datediff(mm, 0, @date1), 0)

    and EndDate < dateadd(mm, datediff(mm, 0, @date1) + 1, 0)

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/