Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current month records from ORACLE since first date.?

Tags:

sql

oracle

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
  • In my application just send only sysdate as parameter. no need to SYSDATE-30. need 1st date to SYSDATE

here shows my two tables sales_header table enter image description here

sales_details table enter image description here

like image 764
Priyan RockZ Avatar asked Feb 27 '14 06:02

Priyan RockZ


People also ask

How do I get the current month from a previous date in SQL?

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.

How do I get the first date of the month in PL SQL?

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.

How do you get the first and last day of the previous month in Oracle?

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.


2 Answers

try this:

WHERE entered_by='2254'
AND ENTERED_DATE BETWEEN trunc (sysdate, 'mm')/*current month*/ AND SYSDATE
like image 55
i100 Avatar answered Sep 27 '22 18:09

i100


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)

like image 34
Mudassir Hasan Avatar answered Sep 27 '22 16:09

Mudassir Hasan