Print Page | Close Window

"Contains" as a formula

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=12321
Printed Date: 18 May 2024 at 8:25pm


Topic: "Contains" as a formula
Posted By: andy.jay
Subject: "Contains" as a formula
Date Posted: 15 Feb 2011 at 4:19am
Hi folks,

I'm trying to write a formula which will inform me if certain text is within a field i.e.
if XXXXXX contains "GR" then "GR" else "0"

I know contains isn't valid but does anyone know what I could substitute in its place and get the same result?

Tanks in advance,

AJ



Replies:
Posted By: DBlank
Date Posted: 15 Feb 2011 at 4:28am
instr()
or
like
if instr({table.field},"GR")>0 then "GR" else "0"
 
if {table.field} like "*GR*" then "GR" else "0"


Posted By: DBlank
Date Posted: 15 Feb 2011 at 4:29am
note that instr() is case-sensitive by default but can be changed


Posted By: andy.jay
Date Posted: 15 Feb 2011 at 4:46am
Excellent, many thanks for that. After 6 years using Crystal, it never surprises me when I learn something new :-) Many chunks of hair saved from my scalp :-)



Print Page | Close Window