Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: NOT BETWEEN substitute in Crystal XI Post Reply Post New Topic
Author Message
kctc
Newbie
Newbie
Avatar

Joined: 09 May 2014
Location: United States
Online Status: Offline
Posts: 3
Quote kctc Replybullet Topic: NOT BETWEEN substitute in Crystal XI
     Posted: 09 May 2014 at 7:17am
In my WHERE section in my SQL script I have a statement that uses NOT BETWEEN and I need to convert into my Crystal Report which is not an option in Crystal. Any suggestions on how to do this?
 
Basically I have a date field that I am checking to make sure it is not between the first day of the current month in the prior year AND the last day of the current month in the prior year. So if this was ran today then I am checking to make sure my date field is not between 05/01/13-05/31/13. Clear as mud? Wink
 
Table_Name.Date_Field  NOT BETWEEN (TRUNC(ADD_MONTHS (LAST_DAY(SYSDATE)+1, -13)) ) AND (TRUNC (ADD_MONTHS( LAST_DAY (SYSDATE), -12)))
 
Thanks in advance!
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 09 May 2014 at 2:02pm
this should work

not (
Table_Name.Date_Field in
dateserial(year(
dateadd("yyyy",-1, currentdate)
),month(currentdate),1)
to
dateadd("d",-1,
dateserial(year(
dateadd("yyyy",-1, currentdate)
),month(currentdate)+1,1)

)
)
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 May 2014 at 3:41am
as an fyi I believe you can simplify this using dateserial without requiring the use of dateadd with in it.
 
NOT (
table.datefield IN
dateserial(year(currentdate)-1,month(currentdate),1)
to
dateserial(year(currentdate)-1,month(currentdate)+1,1-1)
)
IP IP Logged
kctc
Newbie
Newbie
Avatar

Joined: 09 May 2014
Location: United States
Online Status: Offline
Posts: 3
Quote kctc Replybullet Posted: 12 May 2014 at 7:42am
Thank you both for your help!!
 The only part I am not getting correct is in the following statement I need to return the last day of the month. Is there a function that I can use to return the last day of the month? I am not finding that so far.
 
NOT (
table.datefield IN
dateserial(year(currentdate)-1,month(currentdate),1)
to
dateserial(year(currentdate)-1,month(currentdate)+1,1-1)
)
 
Thanks in advance!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 May 2014 at 7:46am
the second part of the to is that...
dateserial(year(currentdate)-1,month(currentdate)+1,1-1)
IP IP Logged
kctc
Newbie
Newbie
Avatar

Joined: 09 May 2014
Location: United States
Online Status: Offline
Posts: 3
Quote kctc Replybullet Posted: 12 May 2014 at 7:49am
Yes I saw that right after I posted. Makes total sense now. Thank you!
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum