SQL Query-return current month and the same month of last year

hello-
I would like to display the current month name, count of errors, year, and month number for both current year and previous year. Having trouble getting my query to display as following..... 
Month   CountofErrors      Year      MoNo
January                  57    2015          1
January                 155   2014          1
thank you!

Its hard to answer without DDL and DML and sample data.
Give a try
select DATENAME(month,getdate()),Month(getdate()),YEAR(getdate()) ,COUNT(*) from dbo.errortable
where DATENAME(month,getdate())='January' and YEAR(getdate()) in(YEAR(getdate()),YEAR(getdate())-1)
group by DATENAME(month,getdate()),Month(getdate()),YEAR(getdate())
--Prashanth

Similar Messages

  • Query with the days of a period and the same days of last year

    I need a help.
    We have a sales cube with daily values.
    We have a query that restricts a month (0CALMONTH) and shows the daily values for this month.
    No problem, we have only to put 0CALDAY on the line and the value on the columns.
    But we need also to show the values of the same days from last year.
    Example:
    The restricted month is july/2011.
    0CALDAY is on the line, so the query shows the values for
    01.07.2011   110,00
    02.07.2011   108,00
    31.07.2011   109,00
    How can we show in the same line the values for july/2011 and july/2010?
    Example:
             July/2010    July/2011
    01     95,00            110,00
    02     96,00            108,00
    31    94,00             109,00.
    Thanks in advance
    César Menezes

    Thanks for the answers until now.
    Surely a Day characteristic (ex. CA_DAY, derived from 0CALDAY) would work.
    But we have this requirement in many other cubes (I posted only an example) and it's not feasible to create this characteristic now.
    I understood the other suggestions, but the problem is not on selecting the values.
    We have two restricted key figures, one for a period (filled by the users) and another one for this period - 12.
    They work OK and bring the correct results.
    The problem is on presenting the results, because as we have 0CALDAY in the line the results appear on two different lines.
    Example:
    15.07.2010    950,00
    15.07.2011    980,00.
    Is ther any way to present the results in the same line?
    Example:
    15.07.2011    950,00 (last year)     980,00 (today)
    or
    15.07             950,00 (last year)     980,00 (today)
    or any other way?
    César

  • OBIEE 11g - Current year date and the same date in Previous year

    Hi Experts,
    I have an attribute say RECEIPT NO, i want to display the "No of Receipts" i.e(count(receipt no)) for any given date in the current year as well as for the same date in previous year.
    Please suggest me how to achieve this in 11g.
    Thanks

    Hi Veeravalli,
    Thanks for your prompt help.
    Could you please ellobarate this. I have to display the count(receipt_no) for the last year same date.
    Thanks

  • SQL Query returns values like "---" and "NA"

    Hi
              When I execute a sql query in MII it returns values like "---" and "NA" for empty Char and numeric fields respectively.
    I have checked the database and made sure that these fields does not have any value. This happens only when I run the query through MII. Can any one know how can we get rid of these values?
    Thanks in advance
    Shaji

    Shaji,
    MII sets those values as a default if it discovers null values in a query result. You can change this default behaviour in several ways.
    First, have a look at the document [Setting custom null values in XML|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70628af0-8ec4-2c10-7da2-f451e412dd8f?quicklink=index&overridelayout=true]. Then you may also use SQL functions like [NVL|http://www.techonthenet.com/oracle/functions/nvl.php] to change the value directly in the SQL query. You can also change the value inside the MII BLT to whatever you need.
    Michael

  • History "today" and "yesterday" are missing--all I get is "Last 7 days", "this month" and the previous month. Is this a matter of settings? If, yes, where do I change it? If not, how might I get any recent history to show?

    Hello,
    As of yesterday I can no longer access any browsing recent history, i.e. history only show me sites visited x-6days (today being the 21 of Sept, I can only see up to the Sept. 15; all sites visited after that date are not displayed).
    I'd be thankful for any answer that may resolve this matter.
    Sincerely,
    D. Hadan

    Make sure that you do not run Firefox in permanent Private Browsing mode.
    *https://support.mozilla.com/kb/Private+Browsing
    *You enter Private Browsing mode if you select: Tools > Options > Privacy > History: Firefox will: "Never Remember History"
    *To see all History and Cookie settings, choose: Tools > Options > Privacy, choose the setting <b>Firefox will: Use custom settings for history</b>
    * Deselect: [ ] "Permanent Private Browsing mode"
    * Select: [X] "Remember my browsing history"
    If you use cleanup software like CCleaner then check the settings for the Firefox application.

  • Returning multiple instances of the same object?

    I have a fairly straight forward swing test class that contains a combobox. The problem is that an object is not selected in the combobox because I get different objects when building the list and when setting the selected item.
    To test this, I've added the following set of 4 lines on three locations in the code:
    - immediately after Toplink is initialized
    - when setting the selected item
    - when the main exits (and the JFrame is open)
    Stand s = Stand.findByPK(4).getDerrivedfromstand();
    System.out.println( s + ", Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
    s = Stand.findByPK(1);
    System.out.println( s + ", Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
    I happen to know that Stand 4 is derrived from Stand 1. So I get Stand 1 once via Stand 4 and once directly. The result is:
    java.vm.version=1.6.0-b105
    [TopLink Info]: 2007.05.30 11:01:10.531--ServerSession(33414193)--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))
    [TopLink Info]: 2007.05.30 11:01:11.343--ServerSession(33414193)--file:/C:/Documents%20and%20Settings/toeu/My%20Documents/kp/reinders/reinders/voorraad/container/bm/build/-reinders login successful
    // immediatly after Toplink init
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@1866417, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@1866417, Standnr=1, Using EM #1a8e53c
    // when filling a combobox in the GUI
    executeQuery: SELECT ... FROM stand ORDER BY standid ASC
    getElementAt 0 = nl.reinders.bm.Stand@1866417, Standnr=1
    // when setting the value of the combobox
    executeQuery: SELECT ... FROM stand ORDER BY standid ASC
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    // when exiting the main (JFrame is open)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    What is amazing is that somewhere after the combobox is filled, the query returns another instance of the same record and thus the select item will not find an "equal" object in the list. Any suggestions?

    Nevermind. A clear was done on the EM somewhere down the line.

  • Sales Summary - Compare same weekday sales last year.

    Post Author: geoffh
    CA Forum: Formula
    I have a table storing invoices going back several years. I wish to calculate the total sales for yesterdays date, & compare it with total sales for the same weekday in the previous year. For example if it is Tuesday today, I need to calculate Mondays total sales (yesterday) & also Mondays total sales for the same week period last year.
    Date fields I have available are 'history.date_invoiced' (invoice date) , history.week_invoiced , history_year.invoiced. Sales values are history.sell_account & history.sell_cash.
    I'm new to crystal.......Using V 11.0.0.1282 . Any help would be greatly appreciated.

    Post Author: yangster
    CA Forum: Formula
    create a formula with the following informationnumbervar weeknumber_curr_year := datepart("ww", dateadd("d", -1, ));numbervar weekdaynumber_curr_year := datepart("d", , 1);  //assuming sunday is the start date of the week, change to 2 if monday isthose 2 variables will tell you the current week number and what day of the week you are after for the current yearnumbervar last_year := dateadd("yyyy", -1, currentdate);if year() = last_year and datepart("ww", ) = weeknumber_curr_year anddatepart("d", , 1) = weekdaynumber_curr_year then amt_field else 0put that in the details section and create a summary of the formula and you should have the total sum of sales for exactly the same week and day of week one year prior to yesterdaymaybe kai has a more simplified solution but that's what comes off the top of my head

  • Creation of a Query to show the values for the current month and the last 12 months data.

    Dear All,
    Good day!
    I have to create a Query with the below requirement.
    I have to create a Query to show the values for the current month and the last 12 months data.
    Can you please guide me how to achieve this ??
    thank you,
    Regards,
    Hema

    Hema
    explain the exact problem..? as you mentioned you want to create query to show values for current month and last 12 months.. so I think you want to show values for 12 months from current data.. you can achive this by multiple way..
    you can have selection screen and field with date .. and restrict based on system current date and 12 months before or you can handle this at your target.. .. I mean there are multiple ways to restrict data by date range..
    for some more hints..
    http://www.forumtopics.com/busobj/viewtopic.php?t=34393&sid=7fba465d0463bf7ff5ec46c128754ed6
    http://businessintelligence.ittoolbox.com/groups/technical-functional/cognos8-l/how-to-display-last-12-months-in-report-based-on-todays-date-3231850
    http://scn.sap.com/thread/3217381
    search on SDN you will get many other ways..
    Thanks,
    Bhupesh

  • How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column

    Please Help!!!
    How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column.
                                      January 2014         January
    2013                            +/-
                    Region   Entry   Exit  Total    Entry   Exit   Total   (Total of Jan2014-Total of Jan2013)
                    A               2         3      
    40        5       7        30                    40-30= 10

    What is a table structure? Sorry cannot test it right now..
    SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
    FROM tbl
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Parent (Global) and Current (Navigation) on the Same Page

    Hello,
    I am using the managed metadata feature in a SharePoint 2013 publishing site.  I am trying to layout my navigation as shown in the diagram below.  I can not find a publishing master page that implements this parent child relationship.  My
    top navigation is use the markup:
    <PublishingNavigation:PortalSiteMapDataSource ID="topSiteMap" runat="server" EnableViewState="false" SiteMapProvider="GlobalNavigationSwitchableProvider" StartFromCurrentNode="false" StartingNodeOffset="0"
    ShowStartingNode="false" TrimNonCurrentTypes="Heading"/>
    <SharePoint:AspMenu ID="TopNavigationMenu" runat="server" EnableViewState="false" DataSourceID="topSiteMap" AccessKey="&lt;%$Resources:wss,navigation_accesskey%&gt;"
    UseSimpleRendering="true" UseSeparateCss="false" Orientation="Horizontal" StaticDisplayLevels="1" AdjustForShowStartingNode="true" MaximumDynamicDisplayLevels="1" SkipLinkText=""/>
    I have tried using the same markup, using a different StartingNodeOffset and SiteMapProviders, for the side menu with no success.
    Thanks,
    Bob

    Hi,
    According to your post, my understanding is that you wanted to create Parent (Global) and Current (Navigation) on the Same Page.
    You can make quicklaunch work contextually like structural nav quicklaunch using Managed Metadata navigation. Please refer to:
    Managed Metadata Navigation - How do you make quicklaunch work contextually like structural nav quicklaunch?
    In addition, you can used JQuery and CSS to achieve staticlevel left navigation in SharePoint 2013.
    Here is a similar thread for your reference:
    http://social.technet.microsoft.com/forums/sharepoint/en-US/54edc501-0594-49e3-86b2-40ecf72bc68e/show-2-level-hierarchy-in-managed-navigation-menucurrent-navigation-in-sharepoint-2013
    More information:
    Overview of managed navigation in SharePoint Server 2013
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • I have 2 iPhones - one for personal use and one for work. They are currently connected with the same Apple ID. I would like to separate the two accounts. Does anybody know how to do this?

    I have 2 iPhones - one for personal use and one for work. They are currently connected with the same Apple ID. I would like to separate the two accounts. Does anybody know how to do this?

    Just create a new AppleID for your work.
    As Allan suggested, items purchased on one iTunes account cannot be moved to the other account.
    However, you can put items purchased on on account onto the other iPhone.

  • I have a pdf registration form on my website.  It has a link that take the user to a payment page within my website.  They pay then submit the form.  The link currently opens in the same browser tab as the form and the user thinks that is the submission,

    I have a pdf registration form on my website.  It has a link that take the user to a payment page within my website.  They pay then submit the form.  The link currently opens in the same browser tab as the form and the user thinks that is the submission, which it is not.  I want my link to open into a new browser tab.  How do I do that?

    You can use the following JS code:
    app.launchURL("http://www.example.com", true);

  • My iphone safari history, my 'reading list' shows visits and sites that I have never frequented. A few months back the same thing happened with my youtube history.  My phone is pass protected, so its just me using it. any ideas?

    My iphone safari history, my 'reading list' shows visits and sites that I have never frequented. A few months back the same thing happened with my youtube history.
    My phone is pass protected, and its just me using it, phone with me all the time. any ideas?
    How can things be added to my reading list/youtube???

    Try:                                               
    - iOS: Not responding or does not turn on           
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try another cable                     
    - Try on another computer                                                       
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar
    The missing apps could have been done by setting the Restrictions that can hid those apps. If the backup was made with those retrictions set the the Restrictions are also restored.
    Thus, if you get it to work restore to factory settings/new iPod, not from backup                               
    You can redownload most iTunes purchases by:        
      Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • TS4036 I tried to restore my iPad from the cloud backup but the iCloud returned the following message 'no backup available'? This after happened after I created the backup today and the same was confirmed at the Apple Store attendant

    I tried to restore my iPad from the cloud backup but the iCloud returned the following message 'no backup available'? This after happened after I created the backup today and the same was confirmed at the Apple Store attendant

    Check the console app to see if there are any error messages. I had one app showing an issue (Pet Hotel) the error was (truncated):
    ERROR: Restore message response: 102 rename error: File name too long (63) at path "/var/mobile/Library/SafeHarbor/com.pocketgems.tappethotel/Container/Documents/ savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHis tory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGa meHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/sa vedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHisto ry/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGame History/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/save dGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory /savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHi story/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedG ameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/s avedGameHistory/savedGameHistory/savedGameHistory/savedGameHistory/savedGameHist ory/savedGameHistory/1313349538-pocket_gems_crash_report.txt" (MBErrorDomain/102)
    I manually snyc'ed that particular app and then re-ran the restore and am now the proud owner of a working iphone. Not sure it is the same problem or app but looking in the console was the key!

  • Sales order and return sales order in the same field

    Hi Everybody,
        I have sales sales order and return sales order in the same field ,how can i separate these two orders in the report.
    Your suggestions are appreciated
    Warm Regards
    Shreya

    Both are sales documents and should be separated by document type....i assume that all the documents are sotrd in the same infocube and if you have tha document type characteristic you can separated them directly in a report
    Regards

Maybe you are looking for