View previous topic :: View next topic
|
Author |
Message |
Krishnadeva Reddy
New User
Joined: 14 Nov 2007 Posts: 40 Location: Chennai
|
|
|
|
Hello,
I'm trying to pull data based on the difference between 2 date fields. If Exp_dte is greater than 1 year of Eff_dte then the query should produce the results. Could someone please assist me on this? I tried using DATEDIFF and also in where clause just put the difference between two dates but I either get "SQLCODE = -440, ERROR: NO AUTHORIZED FUNCTION NAMED DATEDIFF HAVING COMPATIBLE ARGUMENTS WAS FOUND" or "SQLCODE = -182, ERROR: AN ARITHMETIC EXPRESSION WITH A DATETIME VALUE IS INVALID"
Sample Table:
Code: |
Clm_Num Eff_dte Exp_dte
A001 01/01/2023 01/01/2024
B002 01/01/2022 01/01/2023
C001 01/01/2021 01/01/2024
C002 01/01/2021 01/01/2023
D001 01/01/2023 01/01/2024
E001 12/01/2023 12/01/2024
E002 11/01/2022 11/01/2025
|
Required Output:
Code: |
Clm_Num Eff_dte Exp_dte
C001 01/01/2021 01/01/2024
C002 01/01/2021 01/01/2023
E002 11/01/2022 11/01/2025
|
|
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
Please, present the real code of your attempts. |
|
Back to top |
|
|
Krishnadeva Reddy
New User
Joined: 14 Nov 2007 Posts: 40 Location: Chennai
|
|
|
|
Queries I tried:
SELECT Clm_Num, Eff_dte, Exp_dte from table1 where DATEDIFF(Exp_dte,Eff_dte) > 1 YEAR;
SELECT Clm_Num, Eff_dte, Exp_dte from table1 where
Exp_dte - Eff_dte > 1 YEAR; |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
re: "NO AUTHORIZED FUNCTION NAMED DATEDIFF HAVING COMPATIBLE ARGUMENTS WAS FOUND"
How are the two columns defined? And what are the acceptable arguements for DATEDIFF? |
|
Back to top |
|
|
Krishnadeva Reddy
New User
Joined: 14 Nov 2007 Posts: 40 Location: Chennai
|
|
|
|
Both columns are defined as DATE type.
Is there any other way to get the output through SQL? |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
I posted the required syntax for DATEDIFF - as quoted from the User’s Guide, but my post has been deleted by moderators. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2594 Location: Silicon Valley
|
|
|
|
I forgot what Sergey had posted... but I found an example, something like this:
Code: |
DATEDIFF(YEARS, Eff_dte, Exp_dte ) |
You might need to play with it a little to see what it returns. |
|
Back to top |
|
|
|