Sysdate and Current Month

Hello,
  I have an Oracle statement that returns product information for the past 120 days.

I need to modift the date part so that I get a current "Month to date" data set.
You can see my sysdate part below.  How do I modify this to get only the current month?

SELECT   invc.acct_dt, part.user_part_no, Sum(inv.qty) as QTY
    FROM invc invc, invc_ln_prod_fam inv, part part
   WHERE (    (invc.invc_no = inv.invc_no)
          AND (inv.part_no = part.part_no)
          AND (   (invc.invc_status_cd = 'OPEN')
               OR (invc.invc_status_cd = 'CLOSED')
              )
          AND (invc.invc_type_cd = 'INV')
              and trunc(invc.acct_dt) > trunc(sysdate -120)
         )
GROUP BY invc.acct_dt, part.user_part_no
ORDER BY part.user_part_no ASC
Larry Bristersr. DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ivo StoykovCommented:
Hi lrbrister,

to_number(to_char(SYSDATE, 'yyyymm'))

I thibk it is better to include year too because ortherwise feb 2006 will be less than dec 2005

HTH

I
0
Larry Bristersr. DeveloperAuthor Commented:
ivostoykov,
  I am a SQLServer guy.  Could you please place that code in context with the code below?

and trunc(invc.acct_dt) > trunc(sysdate -120)
0
Ivo StoykovCommented:
Hi lrbrister,

> and trunc(invc.acct_dt) > trunc(sysdate -120)
and to_number(to_char(trunc(invc.acct_dt, 'yyyymm'))) > to_number(to_char(trunc(sysdate -120, 'yyyymm')))

I'm not sure whether you need trunc - it rounds date to 16th date - but it is up to you... take a look

anyway here is without trunc
and to_number(to_char(invc.acct_dt, 'yyyymm')) > to_number(to_char(sysdate -120, 'yyyymm'))

regards

I
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Larry Bristersr. DeveloperAuthor Commented:
ivostoykov,
  I appreciate your quick response.  Maybe I'm not being clear...my fault.

I just want data returned for the current month.  I don't want the "120" calculation returned or used at all.

So whatever the day it is this month...I just get March 2006 data and March 2006 only.

Same applies once the month or April comes.  Whether it's the 1st or the 30th I get the sum total of April data....once Sysdate is within April.
0
Ivo StoykovCommented:
Hi lrbrister,

> h
then you need
and to_number(to_char(invc.acct_dt, 'yyyymm')) = to_number(to_char(sysdate, 'yyyymm'))

for March 2006 data and March 2006 the result will be
200603 (your field) = 200603 (today) and will return true
if your field is from las year then it will looks like
200503 (your field) = 200603 (today) and will return false

hope it is clear...


regards

I
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Larry Bristersr. DeveloperAuthor Commented:
ivostoykov,
  That's the ticket!  Great job.  Thanks and points being awarded now.;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.