Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: how can i write sql expression on formula? Post Reply Post New Topic
Author Message
mina
Newbie
Newbie


Joined: 16 Aug 2009
Location: Egypt
Online Status: Offline
Posts: 11
Quote mina Replybullet Topic: how can i write sql expression on formula?
     Posted: 31 Aug 2009 at 5:35am
hi all
iam using CR2008 with mysql database;

i want to write an sql statement with conditions

like :
select branch_name from branches where branch_id = {?branch_id}

so i can use parameters passed by user to sql expression


thanx for reply
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 31 Aug 2009 at 6:29am
you can't, not in a formula.  You can filter the data for the report using report/selection formulas/record, or you can set a group via a formula, but the formula can only check the value vs the parameter, like:
 
if {branches.branch_id} = {?branch_id} then
 (do something)
 
HTH
IP IP Logged
mina
Newbie
Newbie


Joined: 16 Aug 2009
Location: Egypt
Online Status: Offline
Posts: 11
Quote mina Replybullet Posted: 01 Sep 2009 at 12:44am
can i use sql exprssion instead of that ???

i wanna to use a paramter i get from user into sql expression how can i do that ?


thanx soooooooooo much
IP IP Logged
Jyothi Yepuri
Senior Member
Senior Member


Joined: 11 May 2009
Location: Australia
Online Status: Offline
Posts: 127
Quote Jyothi Yepuri Replybullet Posted: 03 Sep 2009 at 9:58pm
If you are using SQL Command for your report ..then use your above query and create a parameter as branch_id.

Edited by Jyothi Yepuri - 03 Sep 2009 at 10:00pm
IP IP Logged
leoneking
Newbie
Newbie


Joined: 03 Sep 2009
Location: Philippines
Online Status: Offline
Posts: 4
Quote leoneking Replybullet Posted: 03 Sep 2009 at 11:35pm
Hi,
 
Options:
 
1. You can use a view/query in mysql then use that view/query in creating your report. Then create a parameter inside Crystal (new parameter field).
 
2. You can select specific records only in record selection. Then create a parameter inside crysal (new parameter field).
 
Hope this helps.
 
Smile
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 04 Sep 2009 at 6:11am
you can write a stored procedure, this will take the parameter that the user enter and apply it when fetching the data, and you won't get 'extra' records.  Otherwise, you can have the user enter a parameter value and then you can use Report/Selection Formula/Record to filter out all records that don't match the parameter.
 
If you want to list options for the parameter the SQL command is a great way, but if you put a parameter in the SQL command and a parameter in the report, you will hit twice with entering the parameter...just a quirk of Crystal as the SQL command object was not designed as the main tool for fetching data...direct table joins or stored procs...or in my case ADO.Net.
 
HTH
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