Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Table Lookup from Formula Field Post Reply Post New Topic
Author Message
jrisch
Newbie
Newbie


Joined: 10 Mar 2008
Location: United Kingdom
Online Status: Offline
Posts: 9
Quote jrisch Replybullet Topic: Table Lookup from Formula Field
     Posted: 24 Mar 2011 at 7:38am

Is there a way to interrogate the current database within a formula field?

The situation is that I need to obtain a value from a lookup table within the current database, based on a field within my current record. However, I can’t link the lookup table because the field in my current record is a string even though the value is numeric, whereas the link field in the lookup table is a number (integer). Trying to link throws up a type error.

The second problem is that there’s a value that the current record field can have, that is not represented in the lookup table. That’s a “-1” to indicate a special case. I realise that if I could link tables then I would need an outer join.

I can probably handle this by using a hidden subreport with shared variables, but that seems a bit cumbersome. I wondered if there was another way, using an SQL Expression or an SQL Command perhaps. Or some way of running an SQL query in a formula field.

Regards, John
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Mar 2011 at 7:52am
you can use a command and convert the string to a number and join on the converted field.
IP IP Logged
IdoMillet
Groupie
Groupie


Joined: 26 Oct 2007
Location: United States
Online Status: Offline
Posts: 99
Quote IdoMillet Replybullet Posted: 26 Mar 2011 at 6:00am
One of the UFL's (User Function Libraries) listed at http://kenhamady.com/bookmarks.html allows you to use a Crystal formula to dynamically construct an SQL statement, execute it against any ODBC data source, and return the result as a single or concatenated value.
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
www.MilletSoftware.com
IP IP Logged
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