Converting Crystal Report to SSRS - ssrs-2008

Below expression is in crystal report
If {Databasetable.Column1} = "1" then
stringVar x := "G" else
If{Databasetable.Column1} = "2" then
stringVar x := "IN " else
If{Databasetable.Column1} = "3" then
stringVar x := "SH ";
X + {Databasetable.Column2}
I need to convert the above expression to SSRS Expression. Please, could anyone help on this?
Thank You.

Try this:
=Switch(
Fields!DatabaseColumn1.Value = 1, "G",
Fields!DatabaseColumn1.Value = 2, "IN ",
Fields!DatabaseColumn1.Value = 3, "SH "
) & Fields!DatabaseColumn2.Value
Let me know if this can help you.

Related

Crystal Reports - formula of full name to initial name

How to display full name in short form like S.M.John in Crystal Reports.
Ex: Database value = Sammual Mbark John.
Need to display => S.M.John
Thank You
Considering your full name can have 2, 3, n names, I think this formula will do the job:
Stringvar result := "";
Local Numbervar i;
Stringvar Array output:= Split({Your.Field}, ' ');
for i := 1 to ubound(output) do (
if i <> ubound(output) then
result := result + left(output[i], 1) + "."
else
result := result + output[i]
);
result
Example and results:
1) "This Is My Test Name" will be "T.I.M.T.Name"
2) "Kurt Donald Cobain" will be "K.D.Cobain"
3) "Barack Hussein Obama" will be "B.H.Obama"
4) "Sammual Mbark John" will be "S.M.John"

crystal report - if else statement when array is declared: string length error

I'm a noob in Crystal Report.
I'm getting String length is less than 0 or not an integer error.
on left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)
of the code below:
local StringVar mDate;
local StringVar mMonth;
local StringVar mDay;
local StringVar mYear;
if {ORDERCHECKVIEW.LOTNUMBER} = 'N/A'
then 'N/A'
else
mDate:= left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1);
mMonth:= left(mDate,2);
mDay := Mid (mDate,4 ,2 );
mYear := totext(2010 + CDbl (right(mDate,InStr(StrReverse(left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)),"-") -1 )),0,""); // transform 2017
cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
Can anyone please explain what's wrong? I don't think my if-else statement is wrong..
FYI, I have previously asked a question and this question is a follow-up:
(Advanced conversion of a single number to year, along with hyphen)
compounded if-else
local StringVar mDate;
local StringVar mMonth;
local StringVar mDay;
local StringVar mYear;
if {ORDERCHECKVIEW.LOTNUMBER} = "N/A"
then "N/A"
else
(
mDate:= left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1);
mMonth:= left(mDate,2);
mDay := Mid (mDate,4 ,2 );
mYear := totext(2010 + CDbl (right(mDate,InStr(StrReverse(left({ORDERCHECKVIEW.LOTNUMBER},InStrRev ({ORDERCHECKVIEW.LOTNUMBER},"-" )-1)),"-") -1 )),0,""); // transform 2017
// cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));
ToText(cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay)),"MM/dd/yyyy") ;
)

crystal reports switch statement not responding properly

Why is my code not properly reading a value in a Switch statement? Code below.
I've verified that it's properly iterating, one character at a time and that the numeric characters appear to match the conditionals. But every character is handled by the default, none by the conditional.
Local StringVar inString := "X12y1023" ;
Local StringVar outString;
Local NumberVar i :=1;
...
While i <= Length(inString)
Do (
Local StringVar inC := mid(inString, i, 1);
Local StringVar outC;
Switch(
inC = "1", outC := "!",
inC = "2", outC := "Z",
inC = "3", outC := "E",
...
inC = "0", outC := "O",
True, outC := inC
);
outString := outString + outC;
i := i+1;
);
outString;
To demonstrate that the number characters are not being read at any point above the default condition (and the length of each iteration is only one character), I modified True as follows:
True, outC := inC + "_" + Cstr(Length(inC)) + ", "
Output generates
X_1, 1_1, 2_1, y_1, 1_1, 0_1, 2_1, 3_1,
What am I missing?
Thanks
A switch statement is not really meant to be used the way you're trying to use it; It's meant for returning simple values and not for more complicated statements, like variable assignments. I'd guess that the behavior you're seeing is probably just a byproduct of the specific implementation of the function.
Instead, you can either use the case-statement or rearrange your switch so that it is only used to return simple values.
//Your code changed to use a case-statement
Local StringVar inString := "X12y1023" ;
Local StringVar outString;
Local NumberVar i :=1;
While i <= Length(inString)
Do (
Local StringVar inC := mid(inString, i, 1);
Local StringVar outC;
Select inC
Case "1" : outC:="!"
Case "2" : outC:="Z"
Case "3" : outC:="E"
Case "0" : outC:="O"
Default : outC:=inC;
outString := outString + outC;
i := i+1;
);
outString;
Or
//Your code rearranged to use switch as intended
Local StringVar inString := "X12y1023" ;
Local StringVar outString;
Local NumberVar i :=1;
While i <= Length(inString)
Do (
Local StringVar inC := mid(inString, i, 1);
outString := outString +
switch(
inC = "1", "!",
inC = "2", "Z",
inC = "3", "E",
inC = "0", "O",
True, inC);
i := i+1;
);
outString;

Display Serial Number as Roman letters in Crystal Reports

need to display serial no as roman letters(i,ii,iii,iv etc) in my crystal reports. I have the serial number captured as record number (1,2,3,4...).so what i have to do for it in crystal report.
Just use the Roman() function provided by Crystal Reports
I can't take much of the credit; I simply ported the code from this VB Helper article into Crystal, but it was a fun exercise:
NumberVar iCounter := 0;
Local StringVar ch := "";
Local NumberVar result := 0;
Local NumberVar new_value := 0;
Local NumberVar old_value := 0;
Local StringVar temp := "";
temp := UpperCase({?#Roman});
old_value = 1000;
For iCounter := 1 To Len(temp) do
(
// See what the next character is worth.
ch := Mid(temp, iCounter, 1);
if ch = "I" then new_value := 1
else if ch = "V" then new_value := 5
else if ch = "X" then new_value := 10
else if ch = "L" then new_value := 50
else if ch = "C" then new_value := 100
else if ch = "D" then new_value := 500
else if ch = "M" then new_value := 1000;
// See if this character is bigger
// than the previous one.
If new_value > old_value Then
// The new value > the previous one.
// Add this value to the result
// and subtract the previous one twice.
result := result + new_value - 2 * old_value
Else
// The new value <= the previous one.
// Add it to the result.
result := result + new_value;
old_value := new_value;
);
// Format the number without commas or decimals
ToText(result, 0, "");
Simply replace my {?#Roman} parameter placeholder with your variable, and you're all set.
I tried to fix it [enter image description here][1]
<https://www.tek-tips.com/viewthread.cfm?qid=887691>
or
<https://www.tek-tips.com/viewthread.cfm?qid=1613334>
and
<https://www.youtube.com/watch?v=X_UaulmICtM&list=TLPQMTUwMjIwMjMRAYZJzCsXDQ&index=6>
specifically: at crystal report
TH1: Fomula fields/new/"nameabc"/enter/"Roman(GroupNumber)"/ ctrl+S/and pull it out
TH2: Fomula fields/new/"nameabc"/enter/
select GroupNumber
case 1 : " I"
case 2 : " II"
case 3 : " III"
case 4 : " IV"
case 5 : " V"
case 6 : " VI"
case 7 : " VII"
case 8 : "VIII"
case 9 : " IX"
case 10 : " X"
case 11 : " XI"
case 12 : " XII"
case 13 : "XIII"
case 14 : " XIV"
case 15 : " XV"
case 16 : " XVI"
case 17 : "XVII"
default : ""
/ ctrl+S/and pull it out
But it really doesn't help t so there will be this 3 case (t improved from link 2-3) it can apply to the 3rd or even 10th group of headings
TH3: ex: (you want to create a text message for group 3)
Formula fields/new/"nameabc"/enter/
"
WHILEPRINTINGRECORDS;
GLOBAL NUMBERVAR INTSTTGRTEST;
INTSTTGRTEST :=0;
/ ctrl+S/ drag it out and put it in heading group 2 and hide it (= right click/format field/common/ check Suppress/ok) you can go to link 3 to see
Formula fields/new/"nameabcd"/enter/
"
WHILEPRINTINGRECORDS;
GLOBAL numbervar INTSTTGRTEST := INTSTTGRTEST + 1;
stringvar y;
STRINGVAR ARRAY X := ["A","B","C","D","E","F","G","H","I","J","K", "L","M","N","O","P","Q","R","S","T","U","V","W","X ","Y","Z"];
if INTSTTGRTEST <= 26 then (
redim preserve X[INTSTTGRTEST];
y := X[INTSTTGRTEST]
);
y;
/ ctrl+S/and pull it out and place it at group 3
and the alphabet can be whatever we want. ex:
X := ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI" ,"XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX","XXI","XXII","XXIII"," XXIV","XXV","XXVI","XXVII","XXVIII","XXIX","XXX","XXXI","XXXII","XXXIII","XXXIV","XXXV","XXXVI" ,"XXXVII","XXXVIII","XXXIX","XL","XLI","XLII","XLIII","XLIV","XLV","XLVI","XLVII","XLVIII"," XLIX","L"];
or
X := ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
hope it can help you
enter code here [1]: https://i.stack.imgur.com/OeBBQ.png

'The string is non-numeric' error in a crystal reports Formula

I have put a formula to display the value of a field after masking it in crystal reports. but it shows me an error 'The string is non-numeric' in cardno variable. Following is code of my formula:
StringVar cardno;
NumberVar current_len;
NumberVar card_len;
NumberVar start;
NumberVar last;
StringVar ca;
card_len := ToNumber (Mid ({#lens},1,2));
start := ToNumber (Mid ({#lens},3,2));
last := ToNumber (Mid ({#lens},5,2));
current_len := Length (Trim (ToText({CA.CA}, 0 ,'')));
ca := ReplicateString("0",card_len-current_len) + Totext({CA.CA},0,'');
If card_len > current_len Then
If start = 0 Then
If last <= 1 Then
cardno := Mid(ca, last, card_len)
Else
cardno := ReplicateString("X",last-start-1) + Mid(ca, last, card_len)
Else
cardno := Mid (ca,1,start) + ReplicateString("X",last-start-1) + Mid(ca, last, card_len);
Please provide a solution to avoid this error. Thanks in advance.
Why don't you do something like this:
Select Len({table.field})
//AmEx
Case 15: Picture({table.field}, "XXXX XXXXXX XXXXX")
//Visa
Case 16: Picture({table.field}, "XXXX XXXX XXXX XXXX")
Default: {table.field}
** edit **
Replace(Space(Len({table.field})-4), " ", "X") + Right({table.field},4)