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?
339 Views Asked by Piolo Quintos At
1
There are 1 best solutions below
Related Questions in SQL
- SQL schema for a fill-in-the-blank exercise
- Hibernate: JOIN inheritance question - why the need for two left joins
- What's supposed to be the problem in this query?
- Compare fields in two tables
- How to change woocomerce or full wordpress currency with value from USD to AUD
- Dynamic query creation with Array like implementation
- SQL query to get student enrolled in this month in a course - Moodle
- SQL LAG() function returning 0 for every row despite available previous rows
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Use row values from another table to select them as columns and establish relations between them (pivot table)
- SQL: Generate combination table based on source and destination column from same table
- how to use system's environnement variables in sql script
- PHP fetchAll on JOIN
- Multitable joining in Sql
- How to display name starting from 'z' by using BETWEEN cmd only?
Related Questions in HANA
- HANA returns Formatted Values through hdbcli
- I am trying to fetch Distinct values into the For loop in SAP HANA and I am not getting all the distinct values into the For Loop
- Hana SQL , Is there a way to use mapping/setup table of constants?
- Delete SAP HANA Views
- Is there any currency conversion function in GCP Bigquery?
- How to implement a encrypted connection to a SAP Hana DB instance in Java
- Hana SQL SAP DSP , can't use standard functions
- SAP HANA, query to check the size of the FullBackup as displayed in the HANA Studio backup catalog
- Why can't I connect to the Hana database through Python but can through Hana Studio?
- HANA Global Temporary tables 'Could not find table/view' error
- How to ingest data from HANA to postgres?
- How to derive the hierarchy output using SAP HANA SQL
- How to connect SAP BW to Jupyter Notebook
- How to get final inserted sql records count using python
- In SQL how to validate dynamic key-value pairs against key-value columns
Related Questions in AMDP
- multiple values as input parameter for CDS consumption view
- HANA-SQL How to get a minimum excluding null vallues?
- Performance of AMDP vs HANA DB procedure?
- MONTHS_BETWEEN('2018-12-31', '2019-02-28') outputs 1?
- Create Dynamic Query in SAP using Table Function
- How to do REDUCE calculation in AMDP method?
- An SQL chalenge
- SAP HANA CX_AMDP_EXECUTION_FAILED Dump SQL code 339 Date SQL
- AMDP Select Query is fetching wrong records
- Summing up column values of rows based on consecutive date in AMDP/MYSQL
- AMDP selects false records contrary to OpenSQL
- When do we have Push down code in SAP Hana
- Extreme values within each group of dataset
- Using REPLACE_REGEXPR in BW transformation throws syntax error
- Calling SP throws "ABAP objects and DDIC objects must be declared in the METHOD statement"
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: