Results 1 to 22 of 22

Thread: [RESOLVED] null dates in formulas

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Resolved [RESOLVED] null dates in formulas

    Please help me if you can!

    I have a formula to display two dates and some text if the dates are not null. But it is not working. The formula is this:

    If isNull({reportview_TimeToTransfer.ExStartDate})
    and
    isNull({reportview_TimeToTransfer.ExEndDate}) Then
    ' '
    Else
    CStr({reportview_TimeToTransfer.ExStartDate}) & ' - '
    & CStr({reportview_TimeToTransfer.ExEndDate}) & ' (Extension)'

    If it worked correctly, it should show:

    01/01/2002 - 12/01/2002 (Extension)

    or if the dates are null, it should be blank. But if the dates are null, it is showing:

    - (Extension)

    Any ideas anyone?!

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: null dates in formulas

    This works fine for me:

    VB Code:
    1. If IsNull({Table1.dtStartDate}) AND IsNull({Table1.dtEndDate}) Then
    2.     ''
    3. Else
    4.     CSTR({Table1.dtStartDate}) & ' - ' & CSTR({Table1.dtEndDate})

    BTW, I am using CR11
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    I'm not sure what version of CR I'm using. It's the bundled version in Visual Studio 2005 (VS version 8.0.50727.42).

    If that formula works for you, why doesn't it work for me? grrrrr I'm really starting to dislike Crystal!!!!

    Do you have any particular settings that I should know about?

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: null dates in formulas

    Quote Originally Posted by obscuregirl
    I'm not sure what version of CR I'm using. It's the bundled version in Visual Studio 2005 (VS version 8.0.50727.42).

    If that formula works for you, why doesn't it work for me? grrrrr I'm really starting to dislike Crystal!!!!

    Do you have any particular settings that I should know about?
    Hmmm, What happens if you put the {reportview_TimeToTransfer.ExStartDate} and {reportview_TimeToTransfer.ExEndDate} next to the Formula Field, do the dates appear?

    BTW, CR is one of the best (and probably one of the more expensive) reporting programs on the market (IMHO or course). Just keep at it you will come to love it for what it can do for your app!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    Thanks for the example. I've tried running it but can't get it to connect to the database you sent. As far as I can see it looks the same as what I have so I have no idea why it's not working!

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: null dates in formulas

    Quote Originally Posted by obscuregirl
    Thanks for the example. I've tried running it but can't get it to connect to the database you sent. As far as I can see it looks the same as what I have so I have no idea why it's not working!
    Did you try putting the two date fields next to the Formula field?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    Quote Originally Posted by Mark Gambo
    Hmmm, What happens if you put the {reportview_TimeToTransfer.ExStartDate} and {reportview_TimeToTransfer.ExEndDate} next to the Formula Field, do the dates appear?

    BTW, CR is one of the best (and probably one of the more expensive) reporting programs on the market (IMHO or course). Just keep at it you will come to love it for what it can do for your app!

    I put it next to the formula field and it only shows if the date is not null which is what I would expect. This is why I'm so mystified about the formula seeming to ignore it!

  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: null dates in formulas

    Quote Originally Posted by obscuregirl
    I put it next to the formula field and it only shows if the date is not null which is what I would expect. This is why I'm so mystified about the formula seeming to ignore it!
    Hmm , I am stumbled. Is there anyway you can zip-up your project and post it?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: null dates in formulas

    What are the datatypes of the date fields? Based on the info they seem to be string fields containing date values rather than true datetime values.

    One of the fields could contain an empty string causing its IsNull statement to return False.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    I've zipped up the report - hope I've done it right! Not sure how to send the database, don't really want to send whole thing, it's quite big! The table I'm using is called StudentExtension and the fields are:

    ExtensionID (int, 4) - Primary key
    ResearchStudentID (int, 4)
    Startdate (smalldatetime, 4)
    Enddate (smalldatetime, 4)

    Thanks for your help!
    Attached Files Attached Files

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    BTW, I've aliased the startdate and enddate fields in my view as ExStartDate and ExEndDate because there are other start and end dates in the view. Forgot to mention that earlier!

  12. #12
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: null dates in formulas

    Are you using a View for this report? Can you post the query.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    ooops! sorry! Forgot that you might need the view as well!!! Doh!

    SELECT YEAR(dbo.ResearchStudent.RegistrationDate) AS RegYear, dbo.ResearchStudent.ResearchStudentID, dbo.Person.Title, dbo.Person.Surname,
    dbo.Person.Forenames, dbo.Person.Initials, dbo.ResearchStudent.Mode, dbo.ResearchStudent.RegistrationDate,
    dbo.ResearchStudent.DateTransferred, DATEDIFF(d, dbo.ResearchStudent.RegistrationDate, dbo.ResearchStudent.DateTransferred)
    AS DaysToTransfer, dbo.ResearchStudent.Active, dbo.StudentExtension.StartDate AS ExStartDate, dbo.StudentExtension.EndDate AS ExEndDate,
    dbo.StudentSuspension.StartDate AS SusStartDate, dbo.StudentSuspension.EndDate AS SusEndDate
    FROM dbo.Person INNER JOIN
    dbo.ResearchStudent LEFT OUTER JOIN
    dbo.StudentExtension ON dbo.ResearchStudent.ResearchStudentID = dbo.StudentExtension.ResearchStudentID LEFT OUTER JOIN
    dbo.StudentSuspension ON dbo.ResearchStudent.ResearchStudentID = dbo.StudentSuspension.ResearchStudentID ON
    dbo.Person.PersonID = dbo.ResearchStudent.ResearchStudentID
    WHERE (dbo.ResearchStudent.RegistrationDate IS NOT NULL) AND (dbo.ResearchStudent.DateTransferred IS NOT NULL)

  14. #14
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: null dates in formulas

    I still think the problem might be the data. Add two formulas, one for each field, to the report to check the null value.

    IsNull({reportview_TimeToTransfer.ExStartDate})

    Do they print True or False when you run the report?

  15. #15
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: null dates in formulas

    Just thought of something else. There is an Report Option that "Converts Null Values to Database Defaults". Is it On or Off?

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    Quote Originally Posted by brucevde
    I still think the problem might be the data. Add two formulas, one for each field, to the report to check the null value.

    IsNull({reportview_TimeToTransfer.ExStartDate})

    Do they print True or False when you run the report?
    They're false where the date is null and blank where the date has a value.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    Quote Originally Posted by brucevde
    Just thought of something else. There is an Report Option that "Converts Null Values to Database Defaults". Is it On or Off?
    It's on.

  18. #18
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: null dates in formulas

    They're false where the date is null and blank where the date has a value.
    ???? Using the formula that I posted that would be impossible. It would either display True or False.

    Run the report with the option to "Convert Null Values.." off.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    Quote Originally Posted by brucevde
    ???? Using the formula that I posted that would be impossible. It would either display True or False.

    Run the report with the option to "Convert Null Values.." off.
    Now it's showing True where the date is null and blank where the date has a value! But the formula is showing blank as I wanted it to where the date is null! Yay!

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: null dates in formulas

    Thanks Brucevde! Once again you've solved my problem! You're a star!

  21. #21
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: null dates in formulas

    Quote Originally Posted by brucevde
    Just thought of something else. There is an Report Option that "Converts Null Values to Database Defaults". Is it On or Off?

    Nice Catch , I didn't even think of that . My hat is off to you sir!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  22. #22
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: null dates in formulas

    Quote Originally Posted by brucevde
    Just thought of something else. There is an Report Option that "Converts Null Values to Database Defaults". Is it On or Off?

    Good knowledge for me also
    Thanks brucevde

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width