Simply shown above, this has been causing inconsistencies with our data. I'm currently writing an AMDP Logic that makes use of the difference between the months of each records, but surprisingly, the function MONTHS_BETWEEN() is not consistent for all cases and were seemingly skipping months for very specific cases. I don't know what is causing this. Is there a way to fix this inconsistency or some sort of alternate solution if none? Thanks.
MONTHS_BETWEEN('2018-12-31', '2019-02-28') outputs 1?
337 Views Asked by Piolo Quintos At
1
There are 1 best solutions below
Related Questions in SQL
- Can MVC.NET prevent SQL-injection at razor or controller level?
- SQL server not returning all rows
- When dealing with databases, does adding a different table when we can use a simple hash a good thing?
- Creating a parametrized field name for a SELECT clause
- Combine two rows based on common ID
- Column displays each count
- Slick query for one to optional one (zero or one) relationship
- Aggregate and count in PostgreSQL
- MAX and GROUP BY - SQL
- SQL statement for a tricky 2 table query
- How to create nested selects with sql?
- Pull and push data from and into sql databases using Excel VBA without pasting the data in Excel sheets
- Best Practice for adding columns to a Table in Oracle database
- SQL FIFO STACK using two tables
- SQL Query - Order by String (which contains number and chars)
Related Questions in HANA
- Is there a way to freeze the entire SAP HANA Database
- Calling R function within SQL - HANA database
- Does SAP HANA support incremental backup
- How to add a (primary) key to an existing table using SAP HANA
- Splitting SQL Columns into Multiple Columns Based on Specific Column Value
- Creating a Scroll_Insensitive ResultSet using the SAP Hana JDBC Driver
- HANA SQLScript dbms_output.put_line() equivalent?
- dynamic fill and create a structure in oData with SAP Hana Calculation View
- Model inconsistency during activation?
- How to use a column list in a database trigger on SAP HANA
- Memory allocation failed: How to combine four result sets into one table
- How to transport HANA Views from one system to another using Hybris
- Hana Parameterised stored proc issue simple jdbc template
- script not running through cron. Works fine when executed manually
- Upload an array in HANA
Related Questions in AMDP
- multiple values as input parameter for CDS consumption view
- SAP HANA CX_AMDP_EXECUTION_FAILED Dump SQL code 339 Date SQL
- Summing up column values of rows based on consecutive date in AMDP/MYSQL
- Performance of AMDP vs HANA DB procedure?
- Using REPLACE_REGEXPR in BW transformation throws syntax error
- How to do REDUCE calculation in AMDP method?
- Table totals to scalar variable in HANA
- Calling SP throws "ABAP objects and DDIC objects must be declared in the METHOD statement"
- When do we have Push down code in SAP Hana
- AMDP selects false records contrary to OpenSQL
- Create Dynamic Query in SAP using Table Function
- AMDP Select Query is fetching wrong records
- SAP HANA SQL SCRIPT Select where in array
- How to pass single-column table to AMDP method?
- MONTHS_BETWEEN('2018-12-31', '2019-02-28') outputs 1?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?

Thanks to the comments, I figured out that the result from the function MONTHS_BETWEEN() is being calculated according to the number of days between. I initially assumed that it only uses the Month's value for the calculation, hence the expectation that Feb 2019 was 2 months away from Dec 2018.
Given that, I was able to come up with quite a fix that converts the dates into the first day of the month to get a guaranteed difference in months for any two given date values.
Here's a snippet of the SQL Code and the corresponding result:
This workaround is followed by an assumption that the dates being compared are all the last days of any given month. If that's not the case then a pre-processing by using the LAST_DAY() function will be needed to be inserted inside the NEXT_DAY() function in order for it to work similarly.
***EDIT: Manually editing the string date value using LEFT() and CONCATENATING with '01' seems to be a more efficient and straightforward approach. I can't upload the screenshot but here's the working code: