Trying to add month with a Date

Hi All,
I am trying to add month with a date. it will take the earlier month and add one month . Here is my code
declare @CollectionDate date='10-30-2014'
select @CollectionDate
;WITH CTemp AS (
SELECT TransactionDate=CAST(@CollectionDate AS DATE) ,RemainingTransaction=1
UNION all
SELECT TransactionDate=DATEADD(MONTH,1,CONVERT(date, CONVERT(varchar(4), YEAR(TransactionDate))
+'-'+CONVERT(varchar(2),MONTH(TransactionDate))
+'-'+ CONVERT(varchar(2),DATEPART(day, @CollectionDate)))),
RemainingTransaction+1
FROM CTemp
WHERE RemainingTransaction < 9
select * from CTemp
When I am giving date 10-28-2014 then it is working fine. But when the date is 10-31-2014 then it shows me the error
Msg 241, Level 16, State 1, Line 3
Conversion failed when converting date and/or time from character string.
I can undestand it is for the month of February but how do I overcome it?
Can anyone help me on this?
Thanks in advance!!
Niladri Biswas

Try the below:
--To find the last day of the month, use the below:
declare @CollectionDate date='10-30-2014'
select @CollectionDate
;WITH CTemp AS (
SELECT TransactionDate=CAST(@CollectionDate AS DATE) ,RemainingTransaction=1
UNION all
SELECT TransactionDate=cast(DATEADD(day,-1,DATEADD(month,MONTH(Transactiondate)-1,DATEADD(year,YEAR(TransactionDate)-1900,0))) as DATE),
RemainingTransaction+1
FROM CTemp
WHERE RemainingTransaction < 9
select * from CTemp
--Just to add a month, use the below
declare @CollectionDate date='10-30-2014'
select @CollectionDate
;WITH CTemp AS (
SELECT TransactionDate=CAST(@CollectionDate AS DATE) ,RemainingTransaction=1
UNION all
SELECT TransactionDate=DATEADD(month,-1,TransactionDate),
RemainingTransaction+1
FROM CTemp
WHERE RemainingTransaction < 9
select * from CTemp
EDIT: You may change -1 to 1 if you want the future months.(I am bit confused whether you are looking for previous months or future months.)

Similar Messages

  • Connected webpart - add item with selected data

    Hi!
    I have a page with connected web parts.
    Example:
    List one: Companies
    a address List with companies
    List two: Employees
    A list with employees and a relation to companies (Company name).
    On the view item on companies i have list Employees connected. When i add an item i would like to have the Company name selected in the drop down.
    I have seen examples on using JavaScript but this doesn´t work in SharePoint 2013. Anyone with a solution for this, Jslink perhaps?

    Hi,
    According to your post, my understanding is that you wanted to add item with selected data in connected webpart.
    I recommend to use lookup column in the Employees to add a relation to companies.
    You can check “Yes” under “Require that this column contains information”. Then you need to select an company when you add a item.
    The result is as below:
    If you want to set the defult value for the lookup column, you can use InfoPath and no code.
    For more information, please refer to:
    SharePoint 2010 - Set default value for a lookup column using InfoPath and no code
    In addition, a simple add-on(SharePoint Default Value Add-On) which inject a "default value" section into "Create Column" dialog, seems to be a solution.
    Thanks,
    Linda Li
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Linda Li
    TechNet Community Support

  • Report grouped by month, need months with no data to appear.

    In my report, I have the data grouped on a formula field that concatenates month and year, so all of my months are returned in order with summary data for the months in headder along with the group name. The details are supressed.
    I have two issues.
    1) I need the headders to show up for all months, even months with no data. I've had a similar issue in the past, which I've worked around, but I was grouping based on a finite ordinal set that existed in my database. I simply let in a little more data than I needed, and supressed the extra rows. This isn't going to work here.
    2) I need the zeroed data points to appear in a graph. Right now, the graph just ignores months that don't exist in the dataset, and as a result the time scale isn't an accurate representation of the actual data trend. ie: if Jan was 13, Feb was 0, and March was 13, on the graph, the line is continuous from 13 to 14. For a user who isn't paying attention to the axis would miss that there is actually a zero in there.

    If you download the "Reports that demonstrate subreport functionality" zip file from this link:
    https://websmp230.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/bobj_download/main.htm, there is a report in there called "Creating_Fake_Records.rpt" which may help you.

  • How do I get the home button in Firefox 18.0.1 to open the home pages in existing tabs instead of new tabs? I have tried some add on with no luck.

    I have tried the following Add on - Tab Utilities and Tab Mix Plus.
    Basically on start up of Mozilla, I have five tabs that load. After surfing/working a bit online, I would like to reload the five original tabs back to the original home page/load settings. If I click on the home button, five more tabs load, giving me ten tabs instead of the five original that I desire.
    Are there any other add on that would fix this. I tried the two above but either they do not offer it or I don't know what settings to choose.

    The best way to keep your home page in the tab is to open other links in a new tab with a middle-click.<br />
    Clicking the home page always open a new set, so you would have to close the current tabs first to prevent getting multiple home page sets.<br />
    I don't know if there is still an extension that can open the home pages and replace the current set.
    See also:
    *https://addons.mozilla.org/en-US/firefox/addon/multiple-tab-handler/

  • Trying to add audio with an image..

    I want to have an audio bar with an image attached to it. I built a page with the image seperate from the audio image. It looks just the way I want it (with the audio bar below the image) but when I publish the page it comes out with the audio placeholder box on the top so that it blocks out most of the image. Cant seem to add the image into the audio file placeholder, or get it to publish the layers the way I build them. Been trying to solve this problem forever! Please help, even if the answer is ridiculous and obvious.

    QuickTime Pro can be used to add an image (or many images) to an audio track.
    Takes just a few seconds to make them.

  • Trying to add Chat with Cbox

    Okay, this is what it should be doing (at someone else's site):
    http://agent96.batcave.net/
    This is what it's doing on my site:
    http://web.mac.com/dzari/iWeb/Braam/test3.1.html
    I'm pretty sure that I already know the answer, that iWeb just won't accept Cbox's html..
    I'm thinking of linking my site with an SMF forum. That would be my 'plan B'.
    Has anyone incorporated a chat or forum feature with their site?

    Hi Deborah...
    Are you sure you added the entire cbox html code? And also used the appropriate dimensions for your text box in iWeb? I just added a cbox to my page to see what you were talking about....looks fine...
    http://web.mac.com/jwtseng/iWeb/kate/cbox.html
    Feel free to test it out on my page for yourself. Let me know if anything is not working.
    You need to follow the general directions for adding any external HTML to iWeb pages...
    The general directions are as follows...
    1. Decide where you want your banner and know exactly what dimensions you need for your cbox
    2. Insert a text box onto your page and adjust its size to exactly your dimensions.
    3. Type in some uniquely identifiable text like, "CBOXCODEHERE" without changing the font or anything else...just type it in.
    4. Publish your page with iWeb.
    5. Find the html file associated with your published page (either on your iDisk or in a folder depending on how you published) and open it in any text editor (like Microsoft Word, or Textedit, or anything).
    6. Scroll through the html file and locate your placeholder text, e.g. "CBOXCODEHERE".
    7. Replace the placeholder text with your cbox html code and publish your page.
    That's it. You should see your cbox show up where you placed the text box.
    Please mark this reply as either "solved" or "helpful" with the little buttons in the title bar of this reply if you found it to be of any use.

  • Is there a completely reliable method of adding months to a date in ABAP?

    Does anyone know of a completely reliable and consistent ABAP function module that can be used to add months to a date.  One that will always get the correct last day of the month when requested to add 1 month to the last day of the previous month.  Something as reliable as using the ADD_MONTHS function in Oracle SQL.  I don't want to use any of the specific 'get last day of the month' function modules since the start date may not necessarily be the last day of a month.
    In the past I have trusted the following.  Now they have betrayed me. 
    MONTHS_PLUS_DETERMINE  
    Correctly provides 28.02.09 when adding 1 months to 31.01.09.
    Incorrectly gives me 28.03.09 instead of 31.03.09 when adding 1 month to 28.02.09
    RP_CALC_DATE_IN_INTERVAL and RP_CALC_DATE_IN_INTERVAL_SG
    Both incorrectly give me 01.03.09 when asked to add 1 month to 31.01.09.
    Both incorrectly give me 28.03.09 when asked to add 1 month to 28.02.09.
    We're on ECC6.

    >
    Suhas Saha wrote:
    > Hello Christine,
    >
    > Did you check the method ADD_MONTHS_TO_DATE of the class CL_HRPAD_DATE_COMPUTATIONS ?
    >
    >
    > *     Adds No. of Months to Date
    >       TRY.
    >           CALL METHOD cl_hrpad_date_computations=>add_months_to_date
    >             EXPORTING
    >               start_date = sy-datum
    >               months     = l_v_month
    >             RECEIVING
    >               date       = l_v_date.
    >         CATCH cx_hrpa_violated_postcondition .
    >       ENDTRY.
    >
    >
    > I dont have any idea how ADD_MONTHS function in Oracle SQL works, though ):
    >
    > Hope this helps.
    >
    > BR,
    > Suhas
    That also sometimes works.....but adding 1 month to 28.02.2009 gives me 28.03.2009 and adding 1 month to 29.02.2008 gives me 29.03.2008.
    This is how to use ADD_MONTHS in Oracle SQL - a bit naughty since you have to use native SQL to do it but it ALWAYS seems to work.  I pass a date, month number and + or - into the function module.
    * For use with class based exception CX_SY_OPEN_SQL_DB.
    DATA:
      ex_check_os       TYPE REF TO cx_sy_open_sql_db,
      ex_check_rs       TYPE REF TO cx_sy_native_sql_error,
      ex_result(200)    TYPE C,
      ex_text           TYPE STRING,
      lv_new_date       TYPE datum,
      lv_old_date       TYPE datum,
      lv_months         TYPE I.
      lv_old_date = iv_date.
      lv_months = iv_months.
      IF iv_sign = '-'.
         lv_months = lv_months * -1.
      ENDIF.
      TRY.
        EXEC SQL.
          SELECT to_char(add_months(to_date(:lv_old_date,'YYYYMMDD'),:lv_months),'YYYYMMDD')
          INTO :lv_new_date
          FROM sys.dual a
        ENDEXEC.
        CATCH cx_sy_native_sql_error INTO ex_check_rs.
        ex_text = ex_check_rs->get_text( ).
        ev_error_message = ex_text.
        ev_return = 4.
      ENDTRY.
      ev_return = 0.
      ev_date = lv_new_date.

  • Outlook 2010 - Cannot Add or Create a Data File

    I am trying to Add both an existing Data File (.pst) into Outlook to review the emails, and add a New Email Account with a separate Data File from the Default Outlook.pst File.
    Setup is Windows 7 Pro x64 - Office 2010 Standard
    I already have 5 Email Accounts setup, each with their own Data File, so this did work in the beginning.
    I have tried opening Account Settings/Data Files, clicking on 'Add' and get this error - "An unknown error occurred, error code 0x80070003"
    When I add a New Email Account and leave the 'New Outlook Data File' selection checked for the 'Deliver new messages to:' option I get the same above error.
    When I add a New Email Account and select 'Existing Outlook Data File' for the 'Deliver new messages to:' option and click on the 'Browse' button nothing happens.  I can add the path though in the field and that will create the New Account using that
    Data File.
    Last related issue is if I want to change the Data File for an Existing Account to a New Outlook Data File.  I open Account Settings/Email, Click on an existing account, click on the 'Change Folder' button, then click the 'New Outlook Data File' button
    and nothing happens.
    Kirk

    Hi
    I had the same problem for an end user and I did all of the above:
    1)Reset My Documents to default
    2)Repaired Office\Outlook installation
    3)Uninstalled\Reinstalled Office\Outlook with reboots in between installations
    4)Cleared the user's previous settings
    This finally resolved my issue
    http://autocad.autodesk.com/?nd=blogs&post_id=136093&blog_id=62
    Creating a registry setting
    "HKCU\Software\Microsoft\Office\14.0\Outlook\ForcePSTPath"
    and forcing PST to be created  in the default path
    "C:\Users\username\AppData\Local\Microsoft\Outlook"
    Hope this helps
    MsHarvey

  • Add column with preq number to ALV grid in me53n

    hi all,
    i am trying to add column with preq number (BANFN) to ALV with preq items in ME53N. it is not available in column set, when trying to add by "change layout" button - i dont understand why, when the strcucture MEREQ3211GRID contains it :-(
    i also tried to add new field ZZBANFN into the structure CI_EBANMEM and after that, i could add the new field to ALV through change layout, but it was empty of course. so i implemented EXIT_SAPLMEREQ_001 from MEREQ001, but ZZBANFN is still empty, because this exit is not called when opening ME53N, but when clicking on tab "customer data" in preq item detail.
    how to solve this? is there any exit that is called before displaying the ALV grid?

    Here is some more detail. I included my code from the Enhancement.
    ENHANCEMENT-POINT MM06EFPO_POT_AUFBAUEN_02 SPOTS ES_MM06EFPO_POT_AUFBAUEN INCLUDE BOUND.
       ENHANCEMENT 1  Z_MM06EFPO_POT_AUFBAUEN_1.    "active version
      SELECT SINGLE zz_old_material FROM mara
        INTO pot-zz_old_material
        WHERE matnr = pot-matnr.
    ENDENHANCEMENT.
    You will also need to change the layout in Item Overview to bring your field in.

  • I get an error trying to add ipads to the device enrollment program

    The error returns a csv file with all the serial numbers marked "Device Not Accessible"

    Hi all.
    If you are getting an 'device not accessible' error it is indeed because the ipad serials are not on your re-sellers portal.
    I have today had the same issue on numerous ipads when trying to add them with serial numbers on the DEP portal.
    Your apple re-seller will have to register the ipad serials on their side of the portal and you then should be able to add the ipads via the orders section of DEP.
    I shall be testing this tomorrow so will post an update...:)

  • Trying to add ParagraphFieldElement

    Hi all.
    I'm trying to add TextObject with ParagraphFieldElement to the report wia RAS SDK:
    ParagraphFieldElement boParagraphFieldElement = new ParagraphFieldElement();
    boParagraphFieldElement.setDataSource("GroupName ({Student.Course})");
    boParagraphElements.add(boParagraphFieldElement);
    ...but when i call refreshReportDocument(); throws exception:
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: ---- Error code:-2147467259 Error code name:failed
    it is true to add the object?
    Edited by: tas.nix on Mar 20, 2011 10:27 PM
    Edited by: tas.nix on Mar 20, 2011 10:28 PM

    If you want to add a simpel text field to the report, look at the attached code snippet:
    ISection sectionToAddTo = oReportClientDocument.getReportDefController().getReportDefinition().getDetailArea().getSections().getSection(0);
         // Create the text object
         TextObject oTextObject = new TextObject();
         // Create the paragraph elements for the text Object     
         Paragraphs oParagraphs = new Paragraphs();
         Paragraph oParagraph = new Paragraph();
         ParagraphElements oParagraphElements = new ParagraphElements();
         ParagraphTextElement oParagraphTextElement = new ParagraphTextElement();
         // Set the text value for the text field
         oParagraphTextElement.setText("This is a text field");
         oParagraphTextElement.setKind(ParagraphElementKind.text);
         // fix some wierd defaults and behavior by explicitly setting default font
         FontColor newFontColor = new FontColor();
         Font newfont = new Font();
         newfont.setBold(false);
         newfont.setName("Arial");
         newFontColor.setIFont(newfont);
         oParagraphTextElement.setFontColor(newFontColor);
         oParagraphElements.add(oParagraphTextElement);
         oParagraph.setParagraphElements(oParagraphElements);
         oParagraphs.add(oParagraph);
         oTextObject.setParagraphs(oParagraphs);
         // Now add it to the section
         oTextObject.setLeft(8000);
         oTextObject.setTop(1);
         oTextObject.setWidth(1911);
         oTextObject.setHeight(226);
         oReportClientDocument.getReportDefController().getReportObjectController().add(oTextObject, sectionToAddTo, -1);

  • Function module for adding number of months to the date

    Hi,
    Is there any function module to get the date by adding number of months...
    Regards,
    Yadagiri

    Normally all SAP FM will return that value. As 1 month in general means 30 days only.
    You can check the code in this link for logig of 31 -
    add month in the date to find next date
    Regards,
    Amit

  • Distribute with Reference Data Functu00BAon Parameters

    Dear Consultatns,
    I'm trying to use distribute with Reference Data function.
    But I couldn't use it.
    I have problems about patameters.
    I need a detailed documentation about this function.
    Best Regards

    Hi Mehmet,
    Have you taken a look at the link below
    http://help.sap.com/saphelp_sem40bw/helpdata/EN/09/078a69016311d393850000e8a597a0/frameset.htm
    Hope it helps.

  • Trying to add data to phone with money already on my accout how do i do it

    trying to add data to my phone with money already on my account how do i do it

        Hi joshua1971,
    Let's get this figured out! Do you have Post-Pay or Pre-Pay service with us? If Pre-Pay please call:888-294-6804.
    Thanks,
    AyaniB_VZW
    Follow us on Twitter @VZWSupport

  • I'm trying to add the system date with a Label. What is wrong with the code

    import java.util.*;
    import javax.swing.*;
    public class CurrentDateApplet extends JApplet
         Calendar currentCalendar = Calendar.getInstance();
         JLabel dateLabel = new JLabel();
         JPanel mainPanel = new JPanel();
         int dayInteger = currentCalendar.get(Calendar.DATE);
         int monthInteger = currentCalendar.get(Calendar.MONTH)+1;
         int yearInteger = currentCalendar.get(Calendar.YEAR);
         public void init()
              mainPanel.add(dateLabel);
              setContentPane(mainPanel);
              dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
                        (Calendar.MINUTE);
    }

    As for what's wrong with the code, it would be easier if you said: it doesn't show the date (it does this instead), it doesn't compile (I get this message) etc.
    Anyway I'll assume you want to display the time in a label...
    dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
    (Calendar.MINUTE);This won't compile: the parentheses are mismatched, and there is simply no such thing as append(). So we could trydateLabel.setText("" + currentCalendar.get(Calendar.HOUR) + currentCalendar.get(Calendar.MINUTE));This wroks, but looks pretty nasty and it's not how you are supposed to format dates and times. Here's the unofficial party line, nicked from one of jverd's posts:
    Calculating Java dates: Take the time to learn how to create and use dates
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format
    From those links you should be able to find those applicable to times like this: http://www.exampledepot.com/egs/java.text/FormatTime.html
    Using this approach you would end up with something like:import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CurrentDateApplet extends JApplet
        private Date date;
        private JLabel timeLabel;
        private JPanel mainPanel;
        public void init()
            mainPanel = new JPanel();
            timeLabel = new JLabel();
            mainPanel.add(timeLabel);
            setContentPane(mainPanel);
            date = new Date();
            Format formatter = new SimpleDateFormat("HH:ss a");
            timeLabel.setText(formatter.format(date));
    }

Maybe you are looking for

  • BOM explosion for Multiple  materials

    Dear All In Cs11 where we can get bom explosion  report for single material,but i need multiple material more than one material as desired. Any Std T code is there.

  • Accessing database on a computer through a phone connected to it

    how to make a moile phone connected to a system access the database on that particular system... i am not able to find any documentation on this...i was reading in cldc specification that it does not support jdbc .. is it possible to have such a case

  • Since updating to 3.6.17, Firefox has twice taken over 50-70% of CPU time. Why?

    I accepted an update to Firefox 3.6.17 a few days ago. Yesterday, and again today, Norton has notified me that Firefox is using an abnormal amount of CPU time. In each case, I confirmed this with Windows Task Manager. For extended periods, the CPU us

  • Ch20l burning light scribe

    I have the above drive on my HP 1070 PC, but it does not recognise Light scribe in any program which I have on the PC. The Drive has the Light Scribe symbol on the front, so my question is. Why cannot any of my software programs use this feature? How

  • GWTDOMAIN terminated and tuxedo not responding.

    I had the following problem once in production      - In one of our Tuxedo server GWTDOMAIN was restarted (dont know the reason)      - After some i started receving message as "Message dropped by gw_msg_recv()" intermettenly but the server was proce