Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: change of records based off another record Post Reply Post New Topic
Page  of 2 Next >>
Author Message
moontide
Groupie
Groupie
Avatar

Joined: 23 Feb 2011
Online Status: Offline
Posts: 78
Quote moontide Replybullet Topic: change of records based off another record
    Posted: 23 Feb 2011 at 1:55pm
My report has buliding structure information in it and has several columns with several tables linked. I am trying to display the building structure Id and the structure number from one table which is linked to another table (one to one relationship) which shows the building ID which is also linked to another table (one to one relationship) to display building Key number. Now the structure Id and buidling Id show equal number side to side and both have 10 digits, the issue is when the fifth and sixth digits change the structure number should change, but it doesn't. Below shows what is going on. The columns are on the detail section because there are several structures for one project which is linked to all the tables.

Prj BuildingKey# BuidlingID   StructureID     Structure#

454   21456       5002100000    5002100000     s-4567
454   21456       5002110000    5002110000     s-4567
454   21566       5002300000    5002300000     s-4567
433   24567       5002390000    5002390000     s-4567
below is what i want to see:

Prj BuildingKey# BuidlingID   StructureID     Structure#

454   21456       5002100000    5002100000     s-4567
454   21456       5002110000    5002110000     s-4567
454   21566       5002300000    5002300000     s-4899
433   24567       5002390000    5002390000     s-4567
I have tried suppressing or using mid functions to extract the sixth digit to change the structure #, but I dont know what formula to use or what can be done to change the structure number everytime the 6th digit changes. The first five numbers remain the same and the last 4 also does remain the same. The first 2 records are the same structure so the structure number is the same which is ok but once the 6th digit is greater then 1 or zero it doesnt change and I tried using the mid function formulas to extract it but how do I force it to change the structure number for the next record when the 6th digit is more than 0 or 1? So any help would be appreciated !


IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 24 Feb 2011 at 11:05am
You said "I am trying to display the building structure Id and the structure number from one table ".  If the structure # comes from a table, shouldn't it be correct ?  In your report, are you printing the structure # from the database or are you trying to build a structure # based on what appears in the structure ID field ? 
 
 
IP IP Logged
moontide
Groupie
Groupie
Avatar

Joined: 23 Feb 2011
Online Status: Offline
Posts: 78
Quote moontide Replybullet Posted: 25 Feb 2011 at 1:03am
Thanks for taking a look into this. The structure # is coming off the database but I want to change the structure # based on the change of the sixth digit of the structure ID and looking for a formula or function in order todo that
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 28 Feb 2011 at 4:02am

I still am not sure what you are trying to do.  In your example of what you want to see, I can't figure out what effect the 6 digit has on the structure number.  Can you give me some pseudo code to describe your logic ? 

In your example the only structure # that changed is the third line where the 6th character is 0.  The first line has a 6th character of 0 but it did not change.  What caused the 3rd line to change the structure # from 4567 to 4899 ?  I know it must have something to do with the 6th character but what is it and where did the 4899 come from ?

IP IP Logged
moontide
Groupie
Groupie
Avatar

Joined: 23 Feb 2011
Online Status: Offline
Posts: 78
Quote moontide Replybullet Posted: 28 Feb 2011 at 5:10am
The first 5 characters of the structure id is the unique identifier of the building and the 6th character is an offset number of the building. If the 6th character is either zero ( 0 ) or 1 then the structure # remains the same but if its neither 1 or 0, for example if its 3 or 2 or any other number then its a different structure # and the structure # is coming off the structure table which has the structure id and structure # in it, linked to the building table which has the building Id linked to the structure id of the structure table.
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 01 Mar 2011 at 3:14am
I am assuming you made a typo in your example and it was supposed to be

454   21456       5002100000    5002100000     s-4567
454   21456       5002110000    5002110000     s-4567
454   21566       5002300000    5002300000     s-4567
433   24567       5002390000    5002390000     s-4899

To reflect what you have described in your second post.

The structure # is coming off the database but I want to change the structure # based on the change of the sixth digit of the structure ID and looking for a formula or function in order todo that


You are retrieving your structure data from the DB. Crystal doesn't change the data on your DB.

You can remove the structure # table field from your report and instead replace it with the formula that you will define that will determine what the # should be.

A formula can change based on the results from the DB; a table field cannot.

Based on what you have described, the logic would be as follows:

-assign the structure# to a variable (data from the table)
-check the sixth digit of your structure ID
-if the digit is 0 or 1, display the variable ("the same as the table")
-else, assign a new value to the variable and display that. (this handles the non 0 or 1 case.)


I don't know how you are choosing to assign values if it is a different structure, so that may involve several things if it's really complex. A really simple implementation would be


local numbervar temp := {table.structure#}; //store original value
local stringvar digit := {table.structureID}[6]; //sixth character
if digit <> 0 and digit <> 1 then //not 0 or 1
   temp := 42 //some random new value I picked to display
temp; //display the value


As I can't imagine what everything looks like because I'm not too experienced with DB's, I can only give you the general algorithm that should produce what you are looking for.

As a general rule, if you want to change data, use a formula and put that on the report in place of the field.

Edited by Keikoku - 01 Mar 2011 at 3:37am
IP IP Logged
moontide
Groupie
Groupie
Avatar

Joined: 23 Feb 2011
Online Status: Offline
Posts: 78
Quote moontide Replybullet Posted: 01 Mar 2011 at 5:32am
Thank you for the algorithm, friend !  I will try it out and see if it works.
IP IP Logged
moontide
Groupie
Groupie
Avatar

Joined: 23 Feb 2011
Online Status: Offline
Posts: 78
Quote moontide Replybullet Posted: 02 Mar 2011 at 3:33am

I have tried using the algorithm yo provided but it seems that the structure # is blank for the some of the structure ID's. e.g

this is what is showing:
 
1. 454   21456       5002100000    5002100000     s-4567
2. 454   21456       5002110000    5002110000     

 
this is what i want :
1. 454   21456       5002100000    5002100000     s-4567
2. 454   21456       5002110000    5002110000     s-4567
 
the second record has a null value for structure ID '5002110000' so in this case how do i force the previous structure # value of 's-4567' onto the second record for the structure #? i tried using 'isnull', 'previous', 'previous is null' formulas, but it doesnt work. Is there a formula that i can force the previous record value onto the next record becaue there are other structure Id's that have a similar combination where the first has a structure # but the second does not and want to include it for those records too. Any help will be greatly appreciated.
IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 02 Mar 2011 at 3:39am
That is odd. Maybe you can post the formula? It shouldn't leave out any values because in the algorithm I gave, the variable is always assigned a value (either the value off the table, or a new value you assign)

The formula would be run at every record, so perhaps there are null values in your DB?

Edited by Keikoku - 02 Mar 2011 at 3:42am
IP IP Logged
moontide
Groupie
Groupie
Avatar

Joined: 23 Feb 2011
Online Status: Offline
Posts: 78
Quote moontide Replybullet Posted: 02 Mar 2011 at 4:27am

the null value is coming off the DB and this is the formula

local stringvar temp := {STRUCTURE.Structure_number}; //store original value
local stringvar digit := {buidling.buidling_id}[6]; //sixth character
if digit = '0' or digit = '1' 
 then //not 0 or 1
   temp := {STRUCTURE.Structure_number};

temp; //display the value
 
with that formula im only getting the the records as shown on post where the second record has a null value for the structure # which is comin off thew DB, so what i want is to force the previous structure # to appear to replace the null values. so my question is how do you replace null values in a record with a previous record where we insert the table.field to replace the null record. Another formula i used to check is
 
if isnull{structure.structure_number} then '-' else{structure.structure_number}
 
But that only shows '-' in the place of the null records but i want to replace the '-' or null records coming from the DB with the previous record above the null value. I dont want to assign a new number for the structure # if its null, it has to be the previous record. So i hope there is a way with this and will be thankful for any help with that

 

IP IP Logged
Page  of 2 Next >>
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.031 seconds.