Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Field formatting question Post Reply Post New Topic
Author Message
ckhan84
Newbie
Newbie


Joined: 30 Dec 2015
Online Status: Offline
Posts: 7
Quote ckhan84 Replybullet Topic: Field formatting question
    Posted: 07 Jan 2016 at 3:44am
Good Morning Everyone,

Been reading this forum on and off for the past few months as I have started report writing and finally had a need to post something that my books and thus far this forum have not been able to help with.

I am writing a report from one database with multiple tables.  The application itself that the DB pulls from allows for custom fields to be created to any table.  However, those application configurations all get dumped into one table titled USERFIELD_STORAGE and in that table there are two fields: UFSFIELDNAME and ALPHA.  UFSFIELDNAME holds the field name as I created it in the application and ALPHA holds the value that is stored in the field. 

Pulling values from this table a bit complex unfortunately leaving me to create a formula field per field to pull from the table based on the left outer join relationship I have.  For example, the formula I have for a field called FileNumber in the application is:

if{USERFIELD_STORAGE.UFSFIELDNAME}="FileNumber"
then{USERFIELD_STORAGE.ALPHA}
else""

What I recently discovered is that all of these fields are stored as string/alpha characters.  So for any date fields that I created within the application (which do work correctly within the app itself) is that they are just stored as an alpha field the in the DB itself.  I am guessing the application configuration that I build within the app translates the field to display it accordingly.

There is one custom field I need to pull titled OriginalStartDate.  When I build my formula field to pull it (similar to what is noted above for the other field), it outputs it as YYYYMMDD format.  I am not sure how to edit this field to have it display as the standard MM/DD/YYYY format that all of the standard date fields in the application display as right now.  Would anyone be able to assist with this?  Please let me know if you have any additional questions.

Thank you very much for your help!
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 07 Jan 2016 at 4:53am
If indeed the the date field is YYYYMMDD, then this is one possible way of converting in a formula.

mid({datefield},5,2)+'/'+right({datefield},2)+'/'+left({datefield},4)

Also since strings are treated like arrays you could do something like this (not tested).

{datefield}[5 to 6]+'/'+{datefield}[7 to 8]+'/'+{datefield}[1 to 4]
IP IP Logged
ckhan84
Newbie
Newbie


Joined: 30 Dec 2015
Online Status: Offline
Posts: 7
Quote ckhan84 Replybullet Posted: 07 Jan 2016 at 5:16am
Originally posted by kevlray

If indeed the the date field is YYYYMMDD, then this is one possible way of converting in a formula.

mid({datefield},5,2)+'/'+right({datefield},2)+'/'+left({datefield},4)

Also since strings are treated like arrays you could do something like this (not tested).

{datefield}[5 to 6]+'/'+{datefield}[7 to 8]+'/'+{datefield}[1 to 4]


Thank you!  I was thinking of something like this (I see other posts with similar suggestions) but how do I do that with my current if/else/then formula that I need to use to find the custom field?

if{USERFIELD_STORAGE.UFSFIELDNAME}="OriginalStartDate"
then{USERFIELD_STORAGE.ALPHA}
else""

Do I need a 2nd formula field to format the field into that format?

Thank you for your prompt help.  I truly appreciate it!
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 07 Jan 2016 at 7:56am
I am assuming that the {USERFIELD_STORAGE.ALPHA} is the date field

if{USERFIELD_STORAGE.UFSFIELDNAME}="OriginalStartDate"
then mid( {USERFIELD_STORAGE.ALPHA},5,2)+'/'+right( {USERFIELD_STORAGE.ALPHA},2)+'/'+left( {USERFIELD_STORAGE.ALPHA},4)
IP IP Logged
ckhan84
Newbie
Newbie


Joined: 30 Dec 2015
Online Status: Offline
Posts: 7
Quote ckhan84 Replybullet Posted: 08 Jan 2016 at 5:20am
Originally posted by kevlray

I am assuming that the {USERFIELD_STORAGE.ALPHA} is the date field

if{USERFIELD_STORAGE.UFSFIELDNAME}="OriginalStartDate"
then mid( {USERFIELD_STORAGE.ALPHA},5,2)+'/'+right( {USERFIELD_STORAGE.ALPHA},2)+'/'+left( {USERFIELD_STORAGE.ALPHA},4)


You are amazing, kind sir.  Thank you so much for the help!  I tried using the DateValue() function in my then statement and once that didn't work, I decided to put up this posting.  Thank you SO much!
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.023 seconds.