Print Page | Close Window

Concatenating strings, Date and Number fields

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=1417
Printed Date: 02 May 2024 at 7:54pm


Topic: Concatenating strings, Date and Number fields
Posted By: jim_rs300
Subject: Concatenating strings, Date and Number fields
Date Posted: 01 Oct 2007 at 10:44am
Hi Everyone,
 
I just wondered if it was possible to concatenate Strings, DateTime and Number fields into a single string?
 
I have found how to concatenate Numbers & strings but not dates.  Would the only way be to use a separate formula to convert the DateTime into a string and then use that in the concatenation or is there an easier way?
 
Thanks in advance!
 
James



Replies:
Posted By: jkwrpc
Date Posted: 01 Oct 2007 at 11:50am
I would simply create the formula and then use the CStr function with the date field. That will change it to a string and you can take it from there.
 
CStr({nameofDateField})
 
Hope this helps.
 
Regards,
 
John W.
http://www.CustomReportWriters.net - www.CustomReportWriters.net
 


Posted By: hilfy
Date Posted: 01 Oct 2007 at 2:55pm
If you need to concatenate data to use for grouping or sorting, you'll have to format the numbers and dates.
 
I usually do this with dates:
 
to_text({datefield}, 'yyyyMMdd')
 
And this with numbers:
 
right('000'+{numberfield}, 3)
 
(This assumes the number's max value is 999 and that it can't be negative.  You can modify it for larger numbers.)
 
-Dell
 


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: wattsjr
Date Posted: 02 Oct 2007 at 8:48am
Hi James -
 
Based on the others responses, I may not have a correct understanding of what it is that you are trying to do, but you might try the following:
 
1.  Create, or insert, a text object into your report.
2. Then right-click on the text object and select "Edit Text Object"
3. Insert (drag & drop) the fields that you want to concatenate.
 
As a test I created a text object containing the following:
 
Text Label + String + Text Label + Date + Text Label + Number (see below)
 
Customer: {CustomerName} was created on: {DateCreated} with ID#: {CustomerID}
 
The text object displayed everything correctly, and all of the parts are fully formatable, so you can format the Name, Date and Number any way that you want them.
 
Is this what you wanted to do?
 
Regards,
 


-------------
-jrw


Posted By: jim_rs300
Date Posted: 02 Oct 2007 at 9:14am
Cheers people.  Advice worked a treat.
 
James



Print Page | Close Window