Professional Documents
Culture Documents
Index:
Index:.........................................................................................................................................................2 Insert Filter.................................................................................................................................................3 Translations of fields.................................................................................................................................3 Change color on every sec line..................................................................................................................3 Second time..........................................................................................................................................4 Suppress data from being showed:............................................................................................................4 IsNull command for date fields.................................................................................................................5 Count unit in a group.................................................................................................................................5 Selection of parameter..............................................................................................................................6 Crystal Report Variable Types................................................................................................................10 IF:.............................................................................................................................................................11 Select a part of a text:..............................................................................................................................11 Inset different color on lines:...................................................................................................................11 Chart.........................................................................................................................................................12 Useful Crystal Report Functions.............................................................................................................14 Change database connection:..................................................................................................................17 Tree search for Maintenance object........................................................................................................20 Full tree search for Position.....................................................................................................................26 Version number.......................................................................................................................................35
page 2 of36
Insert Filter
Is like *-112-118* All record contain -112-118
Translations of fields
A custom filed must be created first. Insert the formula in the formula workshop EG. (this is the translation in Danish) select {Work_history.job_type} case 'P' : "Forbyggende" case 'C' : "Afhjlpende planlagt" case 'U' : "Afhjlpende Uplanlagt" case 'B' : "kondition" case 'I' : "inspektion" case 'O' : "Andre"
Workshop: if Remainder (RecordNumber,2) <> 0 then Color (239, 235, 222) else crNoColor
page 3 of36
Second time
Define a X-1 field. Workshop: E.G. time ({Log_Work_history.Log-time}\3600, (({Log_Work_history.Log-time} mod 3600)\60),0)
In the workshop of the field is put the command; Shared datetimeVar Dato; dato := {Log_Work_history.Log-date}; On the Group section use the section expert:
page 4 of36
Workshop: Shared numbervar TID; Shared datetimevar DATO; if DATO < {Transactions_WS.Create_date} then true else if DATO = {Transactions_WS.Create_date} AND TID < {Transactions_WS.Create_time} then true Else False
The summery will be shown in the group footer. Create textbox next to the group and enter the text 23. december 2008 page 5 of36
Selection of parameter
Create the Parameters in the Field Explore:
EG. Parameter:
page 6 of36
Start the Fomula Workshop and enter the criteria of parameters: Etc: {work_history.start_date} > {?Start}and {work_history.start_date} < {?End}
page 7 of36
Running the report will now show the window for the parameter.
page 8 of36
Variabler
Dim var As dataype; Global StringVar y; A variable's scope determines which formulas have access to that variable. You can set the scope so that a variable can only be used within the formula it's declared in, or you can make it available to the rest of the report. There are three operators that are used to declare scope:
Local/Dim:
The variable can only be seen within the current formula. The variable is private to that formula and can't be used anywhere else in the report. This is the default scope if you don't specify it.
Global:
The variable can be seen within any formula inside the same report. Sub-reports do not have access to the variable.
Shared:
Similar to Global, but the variable can also be seen within sub-reports alle elemet in the report can use a shared variable. You can also omit the Global keyword which creates a Global variable by default:
StringVar y; // Same as: Global StringVar y;
If Formula C is placed in the Report Header and then Formula D is placed in a detail section, Formula C will be evaluated before Formula D. Formula C will be evaluated once and then Formula D will be evaluated for each record appearing in the detail section. Formula C returns 10. For the first detail record, Formula D returns 11. This is because the value 10 of x is retained from when it was set by Formula C. Formula D then adds 1 to this value, setting x to 11 and then returns 11. For the second detail record, formula D return 12, adding 1 to the previously retained value of x which was 11. This process continues for the remaining detail records. The call to WhileReadingRecords tells Crystal Reports to re-evaluate Formula D as it reads in each record of the report. Otherwise, since the formula does not contain any database fields, the program evaluates it only once before reading the records from the database. The formula will then return the value 11 instead of 11, 12, 13, ... as the successive records are processed.
page 9 of36
If the expression x := x + 1 is replaced by x := x + {Orders Detail.Quantity}, you create the effect of a running total based on {Orders Detail.Quantity}, although it is one starting at 10 rather than 0 because of Formula C. In this case, you can omit the call to WhileReadingRecords, since it will automatically occur because the formula contains a database field
myTotal1 in the subreport WhilePrintingRecords; Shared numberVar myTotal1 := 0; Shared numberVar myTotal1 := Sum({tt_sub_ac.budget_costs})
IF:
The If command: IF x then Y else Z EX. Enter a specific PO or return all if {?Purchase order key} > "" then {Purchase_order.PO_key} = {?Purchase order key} and {Purchase_order_line.Purchase_status} = "O" else {Purchase_order_line.Purchase_status} = "O" and {Purchase_order.PO_key} > "-"
Background cooler on the section: if Remainder (RecordNumber,2) <> 0 and count({history_data.rep_key})>0 then Color (239, 235, 222) else crNoColor
page 11 of36
Chart
If haveing a distinct count in the report you can insert a chart directly in the footer section. The char will automatict select the data
page 12 of36
Drag the field that you want to view in the matrix. E.g MO WorkSupplier Transaction amount Down Right Matrix
Group sort expert can be used. ( right click in the empty field top left corner)
page 13 of36
TrimRight(field) Return the string field, without trailing spaces UpperCase(field) Return the string field converted to upper case LowerCase(field) Return the string field converted to lower case ProperCase(field) Return the string field converted to proper case (eg Title Case) StrReverse(field) Return the string field, with all characters reversed (ie last character first) NumericText(field) Returns true if the string is completely numeric (eg 123.45). Returns false if any part of the string is non-numeric (eg 124.23A) ToNumber(field) Converts the field from a string/currency/boolean and returns as a number ToText(field) Convert the field from a number/currency/boolean to a string ToText(field, places) Convert a number/currency field to a string with a set number of decimal places ToText(field, places, thousands) Convert a number/currency field to a string with a set number of decimal places and a character to represent the thousands character ToWords(field) Convert the numeric field to a word representation eg 123 becomes one hundred twenty-three ReplicateString(string, number) Returns the specified string the number of times ReplicateString(xyz, 3) returns xyzxyzxyz Space(number) Returns a number of blank spaces eg Space(10) returns InStr(string1, string2) Returns the position of string2, inside string1 InStr(abcdefgh, de) returns 4 Mid(string, start, length) Returns a part of a string, from start for a certain number of characters. Mid(abcdefgh, 4, 3) returns def
page 15 of36
Left(string, length) Returns the left part of a string to a certain number of characters Right(string, length) Returns the right part of a string to a certain number of characters Chr(number) Returns the ASCII character for the number eg chr(65) returns A Replace(inputString, findString, replaceString) Replaces the part of inputString that matches findString, with replaceString. Replace(abcdefgh, de, xy) returns abcxyfgh Date(YYYY, MM, DD) Returns a Date value for the year, month and day numbers passed in. Year(datetime) Returns the year part of a date or datetime value Month(datetime) Returns the month part of a date or datetime value Day(datetime) Returns the day part of a date or datetime value DateAdd(intervalType, number, datetime) Adds the number of intervals (day, month etc) to the datetime and returns the new date. DateAdd(yyyy, 3, CurrentDate) returns the current date plus three years (eg 30/06/2009) DateDiff(intervalType, startdatetime, enddatetime) Returns the difference between the two dates for the chosen interval. DateDiff(d, {@StartOfYear}, CurrentDate) returns the number of days between 01/01/2006 and 30/06/2006 ie 180) MakeArray(x, y, z, .) Returns an array containing all the items entered MakeArray(abc, 123, xyz) would return an array with three items in it (one for each string). Switch(expression1, value1, expression2, value2, ) Evaluates each expression in turn (must be a boolean result), when the criteria for one is satisfied (is true) it returns thevalue which is associated. Switch({Community.Gender} = M, Male, {Community.Gender} = F, Female, True, Unknown). Note the last expression is just True, this is a default value for when the other expressions are not satisfied. IIF(expression, truepart, falsePart) Evaluates the expression (must be boolean result), if true the truepart is returned, otherwise the falsepart is returned. IIF({@Amount} > 0,Good, Bad) Previous(field) 23. december 2008 page 16 of36
Returns the value of the field, from the prior dataset record Next(field) Returns the value of the field, from the next dataset record IsNull(field) Returns true if the field value is null, otherwise false. PageNumber Returns the current page number of the report TotalPageCount Returns the total number of pages in the report PageNofM Returns eg Page 5 of 10 OnFirstRecord Returns true if the current record is the first one of the dataset OnLastRecord Returns true if the current record is the last one of the dataset ReportTitle Returns the title of the report as entered in File Summary Info Title Useful Crystal Report Formula snippets {vStudents.Surname} + + {vStudents.Preferred} + + ToText({vStudents.ID}, 0, ) - Returns a single string containing the surname, preferred name and ID in the correct order, which can be used for grouping instead of creating a separate group for each field.
page 17 of36
page 18 of36
Select Close
page 19 of36
page 20 of36
page 21 of36
Insert the following command: with sampleorgchart (MO_key,MO_name, POS_root, Root_MO_key, OrgLevel ) as ( SELECT a.mo_key, a.mo_name, a.POS_key, a.root_mo_key, 0 FROM dbo.maintenance_object a WHERE a.POS_key = '' UNION ALL SELECT a.mo_key, a.mo_name, a.POS_key,a.root_mo_key, b.OrgLevel+1 FROM dbo.maintenance_object a INNER JOIN sampleorgchart b ON a.root_mo_key = b.MO_key ) SELECT * FROM sampleorgchart GO Set your curser between Double click on the parameter to the right
page 22 of36
Create the join between the new table and the table you want data from
page 23 of36
page 24 of36
The report will not take data from the position but from all maintenance object below..
page 25 of36
page 26 of36
page 27 of36
The SQL command is combined by tree step Delete table full_tree Create temp table full_tree Create the tree (Recusision)
page 28 of36
drop table Full_tree SELECT position.pos_key, position.root_pos_key, maintenance_object.mo_key, maintenance_object.root_mo_key, maintenance_object.pos_key as POS_key_MO
INTO Full_tree FROM position FULL OUTER JOIN dbo.maintenance_object ON position.pos_key = maintenance_object.pos_key;
with sampleorgchart (POS_key, root_pos_key, MO_key, Root_MO_key, POS_key_MO, OrgLevel ) as ( SELECT a.POS_key, a.root_pos_key, a.mo_key, a.root_mo_key, a.POS_key_MO, 0 FROM dbo.Full_tree a WHERE a.POS_key = '' UNION ALL SELECT a.POS_key, a.root_pos_key, a.mo_key, a.root_mo_key, a.POS_key_MO, b.OrgLevel+1 FROM dbo.Full_tree a INNER JOIN sampleorgchart b ON (a.root_mo_key = b.MO_key or a.root_pos_key = b.POS_key) --INNER JOIN sampleorgchart b ON a.Root_pos_key = b.POS_key --INNER JOIN sampleorgchart b ON a.root_pos_key = b.POS_key ) SELECT * FROM sampleorgchart
page 29 of36
Set the curser in between the and double click on the parameter to the rigth. It is very important that the = {?xxx}
Select OK. (The command must have a valid data to begin with othervise it will give an error..) 23. december 2008 page 30 of36
After the command is created it is important to create the Join between the new table and the selected table (normal procedure).
page 31 of36
page 32 of36
If the parameter should be connected to the list of data in the database it can be don be adding the table and not select a join to it. Then the table can be used to connect to the parameter in the command:
page 33 of36
page 34 of36
Version number
Crystal report 11 Release I
page 35 of36
page 36 of36