here is my code
SELECT h.ENTERED_DATE,
d.DENOMINATION,
sum(h.invoice_total-h.TOTTAL_DISCOUNT)as amount
FROM sales_details d
LEFT JOIN sales_header h
ON d.invoice_id=h.invoice_id
WHERE entered_by='2254'
--HERE IS NEED TO GET DETAILS CURRENT MONTH 1st Date to Sysdate
GROUP BY
ENTERED_DATE,
d.DENOMINATION
ORDER BY
entered_date,
denomination
here shows my two tables
sales_header table
sales_details table
To get the previous month in SQL Server, subtract one month from today's date and then extract the month from the date. First, use CURRENT_TIMESTAMP to get today's date. Then, subtract 1 month from the current date using the DATEADD function: use MONTH as the date part with -1 as the parameter.
Since SYSDATE provides the current date and time, using it as the date parameter for the TRUNC() function and a MM (Month) format model returns the first day of the month because TRUNC() rounds down. First day of the current month. The last day of the current month.
select TRUNC(ADD_MONTHS(SYSDATE, -1),'MM') from dual ; Last Date of previous month (Time Part 23:59:59): SELECT last_day(add_months(trunc(sysdate,'mm'),-1)) + INTERVAL '23:59:59' HOUR TO SECOND FROM DUAL; sql.
try this:
WHERE entered_by='2254'
AND ENTERED_DATE BETWEEN trunc (sysdate, 'mm')/*current month*/ AND SYSDATE
Compare months in where condition
WHERE to_char( sysdate, 'mm' ) = to_char( ENTERED_DATE, 'mm' )
Also
WHERE EXTRACT(month FROM sysdate)=EXTRACT(month FROM ENTERED_DATE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With