How do I combine static text and fields into a single field - crystal-reports

I need to do this for multiple fields and text
So in one field I would want it be TEXT FIELD TEXT FIELD TEXT FIELD
So it would be L 12 X W 12 X 12
The letters would be static text and the numbers would be an actual field
Thanks

You would use a Formula Field to do this. Within the Formula Field you can concatenate plain text with database fields. Here is an example of a formula for a Formula Field.
"This is my custom string." & {table.column} & " more custom text.";
This formula will concatenate the first string contained within the double quotes, the value of {table.column}, and the second string contained within double quotes. If we assume the value of {table.column} is "Delta365", then the output of the formula field would be the following:
This is my custom text. Delta365 more custom text.
EDIT: Response to follow-up question.
To remove the decimal from a numeric value while using a formula to concatenate the numeric value to a string of text you should use one of the overloaded ToText() function. ToText(x,y) is the most commonly used versions of this function. Here is a breakdown of the arguments for this function.
x is a Number or Currency value to be converted into a text string.
y is a Format String that determines how the value of x will be
displayed.
There are two ways to use this function to remove the decimal point. Here is an example of each method using the same example I used previously.
"This is my custom string." & ToText({table.column},0) & " more custom text.";
Or
"This is my custom string." & ToText({table.column},"#") & " more custom text.";
The difference between these two formulas is the value of the y argument. When y = 0, the value of {table.column} will be rounded to the nearest whole number. When y = "#", the value of {table.column} is not rounded and instead will truncate and not show any digits beyond the decimal point.

Related

Cutting off decimals in Year conversion in Crystal Syntax

I'm printing the following year as a string in a report but it prints as 2,018.00. How do I have it print as a four digit year string without decimals or the comma? The Truncate() didn't seem to work.
CStr (Year({Date}) + 1)
You can either omit the CStr-function and set the number format on the formatting tab or, if the formula needs to return a string, you can use the arguments of the CStr- or ToText-function (which are equivalent).
Either set the second argument to define the number format:
CStr(Year({Date}) + 1, "####")
Or
Set the second and third argument to set the number of decimals to 0 and an empty string as thousands separator:
CStr(Year({Date}) + 1, 0, "")
What is happening is the Year() function converts the data into a Number, complete with thousands separator, decimal, and 2 significant digits after the decimal.
To get around this what I have found that works is to remove the CStr() function from your formula. This allows you to access the Formatting tab for a Number data type by right clicking the field and selecting Format Field. Then from the Number tab you can set the Style of the field to one of the styles that doesn't use a separator or decimal in the display.
If you are needing to concatenate this value with another string, then you can get a little more creative and use the LEFT() and REPLACE() functions like this.
Left(Replace(Cstr(Year({Date}) + 1), ",", ""), 4)

converting 1x1 matrix to a variable

I read the data from the csv which contains two columns id which text/string and the cancer which is 1/0. please see the code be
M = readtable('data.csv');
I try to access the very first value using
row= M(n,1); //It's from the ID column which is text
But it comes in the form of a 1x1matrix, and I am unable to put it in a single variable.
for example I want after the above line works row should contain a string in it like. row = 'patientID'. Now is there anyway to convert it into a single value?
Use row = M{n,1}. Note the curly braces.
The curly braces say "get the contents of the table", as opposed to the circular brackets you had been using which say "get me a portion of the table, as a table".

Concatenated number fields in crystal reports

I have 2 number fields in crystal reports that I want to concatenate using a formula field, so in my formula I created a field and added ToText({Table.TOTAL_QTY}) & " / " & ToText({Table.BOX_COUNT}) as the formula. Works fine but the numbers appear with decimals, "9.00 / 12.00". How do I remove the 0's in the formula field?
ToText supports various formatting options. You can pass the number of decimals in the second parameter when the first parameter is a number:
ToText({Table.TOTAL_QTY}, 0) & " / " & ToText({Table.BOX_COUNT}, 0)
From Crystal Reports 2008: The Complete Reference:
ToText (n1, n2, s1, s2)
n1 – a numeric value to be converted to a string.
n2 – a numeric value indicating the number of decimal places to use when converting n1.
This argument is optional.
s1 – a string value indicating the character or characters to use as a thousands separator
when converting n1. This argument is optional.
s2 – a string value indicating the character or characters to use as a decimal separator when
converting n1. This argument is optional.

Crystal report issue with int to string conversion

I want to convert int to string and then concatenate dot with it. Here is the formula
totext({#SrNo})+ "."
It works perfectly but not what i want. I want to show at as
1.
but it shows me in this way
1.00.
it means that when i try to convert int to string it convert it into number with precision of two decimal zeros. Can someone tell me how can i show it in proper format. For information i want to tell you that SrNo is running total.
ToText(x, y, z, w) Function can use
x=The number to convert to text
y=The number of decimal places to include in result (optional). The value will be rounded to that decimal place.
z=The character to use as the thousands separator. If you don’t specify one, it will use your application default. (Optional.)
w=The character to use as the decimal separator. If you don’t specify one, it will use your application default. (Optional.)
Examples
ToText(12345.678) = > “12345.678″
ToText(12345.678,2) = > “12345.67″
ToText(12345.678,0) = > “12345″
You can try this :
totext({fieldname},0)
Ohhh I got the answer it was so simple.
totext takes 4 parameters
First parameter is value which is going to be converted
Second parameter is number of decimal previsions.
Third parameter is decimal separator. like (1,432.123) here dot(.) is third parameter.
Forth parameter is thousand separator. like (1,432) here comma(,) is forth parameter.
Example{
totext("1,432.1234",2) results 1,432.12
totext("1,432.1234",2,' " ') results 1,432"1234
totext("1,432.1234",2,' " ', ' : ') results 1:432,1234
}
Although i think this example may be not so good but i just want to give you an idea. This is for int conversion for date it has 2 parameters.
value to be converted and format of date.

Postgresql, treat text as numbers for getting MAX function result

Still didnt fix issue with dates written as strings here comes another problem.
I have text column where only numbers as writen (like text).
By using function MAX I get incorrect result because there 9 is bigger than 30.
Is here any inline function like VAL or CINT or something that I can compare and use textual data (only numbers) like numbers in queries like SELECT, MAX and other similar?
How than can look like in following examples:
mCmd = New OdbcCommand("SELECT MAX(myTextColumn) FROM " & myTable, mCon)
You need to use max(to_number(myTextColumn, '999999'))
More details are in the manual: http://www.postgresql.org/docs/current/static/functions-formatting.html
If all "numbers" are integers, you can also use the cast operator: max(myTextColumn::int)
If your text values are properly formatted you can simply cast them to double, e.g.: '3.14'::numeric.
If the text is not formatted according to the language settings you need to use to_number() with a format mask containing the decimal separator: to_number('3.14', '9.99')
To get the MAX works poterly you need to first convert your text field in numeric format
mCmd = New OdbcCommand("SELECT MAX(TO_NUMBER(myTextColumn, '99999')) FROM " & myTable, mCon)