Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Query in a formula Post Reply Post New Topic
Author Message
Kausthub R
Newbie
Newbie
Avatar

Joined: 26 May 2009
Online Status: Offline
Posts: 4
Quote Kausthub R Replybullet Topic: Query in a formula
    Posted: 27 May 2009 at 10:33pm

I'm using CR XI

I need to write a query inside a formula field which looks like this,
 
If(Condition1)
then Query1
Else Query2
 
Is this possible?
If not what is the alternative?
 
I have tried a lot but no success.
Please help me out!!!
 
Thanks in advance.
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 28 May 2009 at 1:36am
Hi
 
not sure what you are trying to do,you can try using SQL Expression field and see it  works,not sure of the syntax though .
 
you can also try creating stored procedure which accepts parameter from the report and depending on the parameter value excute the query.
 
Cheers
Rahul
IP IP Logged
Kausthub R
Newbie
Newbie
Avatar

Joined: 26 May 2009
Online Status: Offline
Posts: 4
Quote Kausthub R Replybullet Posted: 28 May 2009 at 3:42am
The expression what i need is like this:
 
if {table.field1}="Value1"
then
(select "table"."field2" from "table" where "table"."field3"="Value3"
and "table"."field1"="Value1")
else
(select "table"."field2" from "table" where "table"."field3"="Value3"
and "table"."field1"="Value2")
 
Value's can be hard coded.
 
Is this possible using a SQL expression field?
 
 
 


Edited by Kausthub R - 28 May 2009 at 4:38am
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 28 May 2009 at 3:48am
Hi
not sure never tried it in SQL Expression,but if you use a word of caution before the report executes it will compile the query to it may take a while before the report fetches the data.
 
What I would suggest is to create a stored procedure and pass parameter from the report and depending on that parameter value execute the select statement in your procedure.
 
Cheers
Rahul
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 28 May 2009 at 6:43am

I doubt that it will work.  Due to the way that Crystal works, it will have already have read the data, and will not read again.

As suggested before, create a stored proc and in it, you can create the field and populate it with the data that is desired.  A view would work as well.
 
Last suggestion, and for something like this, I don't like, but you could create a subreport to get the value that you need....Crystal will do a data read again for a subreport.  Reason I don't like it, it will incur lots of hits to the DB for something that could have been gotten in another manner much more effectively (via view or stored proc).
IP IP Logged
Kausthub R
Newbie
Newbie
Avatar

Joined: 26 May 2009
Online Status: Offline
Posts: 4
Quote Kausthub R Replybullet Posted: 02 Jun 2009 at 9:15pm
Stored procedure must work fine,
Thanks Rahulwalawalkar & Lockwelle for your fast replies.
 
IP IP Logged
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.031 seconds.