I have a switch statement in a Crystal Report that looks like this:
stringvar tag := {table1.field1}; //contains a string value
select tag case
'First Value': {table1.field3}
'Second Value': {table4.field9}
default: 'Unknown';
But when I try to save the formula, I get this error:
---------------------------
Crystal Reports
---------------------------
The remaining text does not appear to be part of the formula.
---------------------------
OK
---------------------------
And it highlights the formula beginning with the single quote before the word "Second" in my example.
What stupid syntax error am I making?
Shouldn't this be written as...
select (tag )
case 'First Value': {table1.field3}
case 'Second Value': {table4.field9}
default: 'Unknown';
?
Note, I just looked the syntax online; I'm not a Crystal Reports specialist...
Related
I'm trying to convert sql case statement to crystal formula.
The select in sql had this in it:
...
,pf.Status_category AS Category
,CASE WHEN p.degree LIKE '%P%' AND
pf.department_name LIKE 'Occ%' THEN isnull(pf.department2, '') ELSE isnull(pf.department_name, '') END AS Department,
CASE WHEN p.degree LIKE '%P%' AND pf.department_name LIKE 'Occ%' THEN isnull(pf.Section2, '') ELSE isnull(pf.Section_name, '') END AS Section,
CASE WHEN p.degree LIKE '%P%' AND pf.department_name LIKE 'Occ%' THEN isnull(pf.department3, '') ELSE isnull(pf.department2, '') END AS [Department 2],
CASE WHEN p.degree LIKE '%P%' AND pf.department_name LIKE 'Occ%' THEN isnull(pf.Section3, '') ELSE isnull(pf.Section2, '') END AS [Section 2],
pdd.DepartmentName AS DP
,pdv.PrivilegeDetailText AS Privilages
...
FROM dbo.Person_PrivDtl_V AS pdv INNER JOIN
dbo.Person_Privs_Facs_V ON pdv.M_ID = dbo.Person_Privs_Facs_V.Person_Priv_M_ID INNER JOIN
dbo.PrivDefDepartments_PDF AS pdd ON pdd.PDDept_ID = pdv.PDDept_ID INNER JOIN
dbo.Person AS p ON pdv.Person_ID = p.Person_ID INNER JOIN
dbo.Person_Facilities AS pf ON pf.FacCode = dbo.Person_Privs_Facs_V.FacCode AND pdv.Person_ID = pf.Person_ID
When I convert this to crystal, I can't put this in the columns of the report design. So my idea is to use a formula for each column selected. I have this so far for the first formula, but it won't let me save it:
Formula name= Department:
select {Person_Facilities.Department_name}
case is like "Occ%" : {Person_Facilities.Department2}
The error seems to be the like. I looked up crystal like and it seems ok except for they use "is" for the accepted answer, but when I add "is" the error seems to be the "is" when I try to save it.
What is wrong with this formula so I can use like and the case?
Is there a better way to do this? I suppose I can use a view, but my boss doesn't want views cluttering the DB. Is using a formula the way to do this in crystal? The sql also handled null, which I'm not doing, but I'm not sure how to incorporate that at this point. I'm pretty new to crystal and my team doesn't like questions. We have Crystal Reports 2008 and SQL server 2008 R2.
Not sure if this is what you are looking for but try this;
select {Person_Facilities.Department_name}
case "Occ%" : {Person_Facilities.Department2}
default : 'Unknown';
The default is optional.
To use the LIKE operator, it is as follows;
If {Command_Main.Name} LIKE '*Manager*' then Do Something
To handle NULLS in CR, there is an option to do so in the formula editor. See below. Change it from Exception for Nulls to Default Values for Nulls.
i have a report I am trying to modify in Crystal. It has a data field that has a formula in it, but I want to use another formula.
how to convert above crystal synax to basic syntax in crystal report
IIF ({rpl_bal_bundlelabels.recordcode} = "2",0 ,
IIF ({rpl_bal_bundlelabels.StdOdd} = "OS",
IIF ({rpl_bal_bundlelabels.totalsupply} > {rpl_bal_bundlelabels.standard},
IIF (({rpl_bal_bundlelabels.totalsupply} mod {rpl_bal_bundlelabels.standard}) > 0,
{rpl_bal_bundlelabels.totalsupply} - (({rpl_bal_bundlelabels.totalsupply} \
{rpl_bal_bundlelabels.standard}) * {rpl_bal_bundlelabels.standard}) ,
{rpl_bal_bundlelabels.standard} ) ,{rpl_bal_bundlelabels.totalsupply} ) ,
{rpl_bal_bundlelabels.BundleCopies} ) )
create a new formula
paste the text
correct the syntax, if necessary
set the result to formula =
Crystal Version: Crystal Reports 2008
I have a string parameter that has multiple options:
Team 1
Team 2
Team 3...
Team 16
I want to show which team(s) the user selects on the report.
User selected: Team 1, Team 5, Team 6, Team 13
The logic I want to use is:
if {?SelectTeam}="All" then "All"
else totext({?SelectTeam})
but obviously, that doesn't work. I have added the parameter to the report and it only shows the first item that is selected. Any suggestions?
Something like this would work since {?SelectTeam} should be an array.
Local StringVar StrTeams := "";
Local NumberVar i; /FTFY
if {?SelectTeam}="All" then "All"
else (
For i := 1 To UBound({?SelectTeam}) Do
(
StrTeams := StrTeams + {?SelectTeam}[i] + " ";
);
StrTeams;
)
IIf ({?SelectTeam}="All", "All", Join({?SelectTeam}, " ") )
I have a simple SQL Server 2008 R2 report with a textbox containing a few fields. I want to suppress the line if the value of a field is null. What would be the syntax for the expression?
So my fields are...
Name
AddressLine1
AddressLine2
AddressLine3
CityStateZip
and I have expressions like this...
=First(Fields!AddressLine2.Value, "dsPersonData")
I was trying the expression below but getting errors
=IIF(Fields!AddressLine2.Value, "",True,False)
In other words I was trying to set the visibility to false if the value was an empty string but I'm not sure what the syntax would be.
you can try
=IIF(First(Fields!AddressLine2.Value, "dsPersonData") is Nothing ,False,True)
Is easy to do this in the sql query, For example:
in SQL Server:
ISNULL(Name, '') as Name
ISNULL(AdressLine1, '') as AdressLine1
ISNULL(AdressLine2, '') as AdressLine2
ISNULL(AdressLine3, '') as AdressLine3
ISNULL(CityStateZip, '') as CityStateZip
and if you want to set the visibility to false:
=IIF(First(Fields!AddressLine2.Value, "dsPersonData") = "",False,True)
I have column its name 'owner' and its has the following vlaue
ownerName
--------
Koni
Sally
Jimmi
Jone
Sami
and i want to print this value in crystal report as following using formula
ownerName
Koni
--Sally
----Jimmi
------Jone
--------Sami
thank you for any help
This can be done by using the following formula criteria:
If (RecordNumber > 1) Then
ReplicateString("-", RecordNumber) + {DatabaseFieldName}
Else
{DatabaseFieldName}