Search code examples
sqlsql-serverdatedayofweekdays

Simple SQL Query: need this month data and previous month last 5 days data together


Need SQL query for this month data and previous month last 5 days data together:

SELECT
  CONVERT(VARCHAR (10), wDate, 103) AS wDate,
  Empid,
  Process,
  Model,
  Qty,
  Section,
  Avlbl_Mins,
  NP_Mins,
  L_Mins,
  NP_Reason       AS NPReason,
  Process_Remarks AS PRem,
  Day_Remarks     AS DRem,
  Othermin,
  StdMin,
  Tstdmin,
  TAvlblmin
FROM tblProductionEffcyDetails
WHERE (DAY(EnteredDate) >= DAY(GETDATE()) - 5)
ORDER BY EnteredDate DESC

Solution

  • Try this : to get data from last months last five days

    WHERE EnteredDate > (DATEADD(DAY,-5,DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0))