Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Specifying String Length Post Reply Post New Topic
Page  of 2 Next >>
Author Message
gitanjali1027
Newbie
Newbie
Avatar

Joined: 01 Apr 2010
Online Status: Offline
Posts: 25
Quote gitanjali1027 Replybullet Topic: Specifying String Length
    Posted: 15 Apr 2010 at 9:29am
I am trying to get the first 25 characters of a string field i have in my report.

I have tried the following: 

{DataTable1.Name} = Left({DataTable1.Name},26)

however i find that instead of showing 26 characters, it is truncating the list of things that is populating my report...so that only 26 items show on my report.  It's kind of an odd problem 

Does anybody else have any ideas on how to specify a string length?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 15 Apr 2010 at 9:31am

Soundls like you are putting this in the Select Expert.

The select Expert is only used to limit data returned.
 
Just add a new formula field (in the field explorer) as:
Left({DataTable1.Name},25)
 
place the formula field on your report canvas to display your desired result


Edited by DBlank - 15 Apr 2010 at 9:32am
IP IP Logged
gitanjali1027
Newbie
Newbie
Avatar

Joined: 01 Apr 2010
Online Status: Offline
Posts: 25
Quote gitanjali1027 Replybullet Posted: 15 Apr 2010 at 9:38am
Ah yes, i was in fact using the Select Expert.  This worked so well, THANK YOU!
IP IP Logged
gitanjali1027
Newbie
Newbie
Avatar

Joined: 01 Apr 2010
Online Status: Offline
Posts: 25
Quote gitanjali1027 Replybullet Posted: 15 Apr 2010 at 9:51am
one thing though--it seems to love to truncate a word in the middle of a letter.  any way to avoid that?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 15 Apr 2010 at 10:14am
What do you want your logic to be to handle it?
Truncate at the first " " after 25 characters?
IP IP Logged
gitanjali1027
Newbie
Newbie
Avatar

Joined: 01 Apr 2010
Online Status: Offline
Posts: 25
Quote gitanjali1027 Replybullet Posted: 15 Apr 2010 at 10:30am
Basically i want to to be that the max length is 25 chars.  Meaning any chars above 25 do not show up (rather than truncate in the middle of the letter).
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 15 Apr 2010 at 10:47am

try this:

left({DataTable1.Name},instrrev(left({DataTable1.Name},25),' ')-1)
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 15 Apr 2010 at 10:50am
Actually that will error if the string is less than 25 and ther is no " "  in it so try:
 
if length({DataTable1.Name})<25 then {DataTable1.Name} else
if lengthleft({DataTable1.Name},instrrev(left({DataTable1.Name},25),' ')-1)
IP IP Logged
gitanjali1027
Newbie
Newbie
Avatar

Joined: 01 Apr 2010
Online Status: Offline
Posts: 25
Quote gitanjali1027 Replybullet Posted: 16 Apr 2010 at 2:46am
I tried the last formula you posted, however I keep getting errors when I tried to put it in the formula.  It kept saying 'A number, currency amount, boolean, date, time, date-time, or string is expected here' and it highlights the lengthleft portion.  
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 16 Apr 2010 at 4:33am
I see a left parathesis missing between length and left in the second if.  Also you have a second if and no then.  And you have a left, but no value for that left.

Edited by kevlray - 16 Apr 2010 at 4:40am
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.047 seconds.