Query by current month

  • I am rather new to working with databases and queries. That being said.....

    I am trying to pull data in from an Oracle data base into an excel spread sheet. I already have the connections and everything, but I cant seem to figure out how to restrict the data to only that in the current month.

    I know i need to add a "where" clause to my query, but I cant find the proper one to insert.

    can someone help me out with this?

    the field that this is bassed off of is a date time field.

  • Something like

    WHERE myDateField <= DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) -- last day of current month

    AND myDateField => DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0) -- first day of current month

    You could also use WHERE MONTH(myDateField) = MONTH(GETDATE()), but the previous one makes better use of indexes (if present on the myDateField column).

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • when i use these i get an error that says "Oralce ODBC Ora -00920 invlaid operational operator

  • I probably used some TSQL function which are not available in Oracle, so you might want to convert some functions to PLSQL.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I will be honest.... I am a complete moron when it comes to this stuff.....

  • This should get you started:

    http://forums.databasejournal.com/showthread.php?49804-getting-first-date-and-last-date-of-previous-month-in-oracle

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • This is not an Oracle forum...

    It will be good if you post your query in proper forum

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • mromano222 (7/12/2013)


    when i use these i get an error that says "Oralce ODBC Ora -00920 invlaid operational operator

    You posted in a SQL server forum 🙂 He gave you a bunch of T-SQL (Transact) statements. I'd suggest moving this thread on over to the Oracle section so that you can get some traction on it. Or depending on what this is for install sql server express and use sql 😛

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply