Converting Crystal Report Formula(if condition) to SSRS

  • Hi,

    Currently I am migrating Crystal reports to SSRS 2008. I am struggling to covert Crystal rpt formulas like below to SSRS. if {table.Subject Parent ID} in [1005,1458, 1031, 1038, 1045, 1051,

    1068, 1077, 1237, 1466, 1467, 1327, 1332, 1328,1001, 1295, 1296]

    Or

    {table.Seq.Subject} in [1005,1458, 1031, 1038, 1045, 1051,

    1068, 1077, 1471, 1466, 1467, 1327, 1332, 1328,1001, 1002,1003,1295,1296]

    then "Business Applications"

    else If

    {table.Subject Parent ID} = 1057 or {table.Seq.Subject} in [1478,1057]

    then "Instructional Applications"

    My question is, how to convert this to SSRS Expression. ( any nice way?) Help me...

    Regards

    Dhans

  • I did like below...

    if (S_PID = 1005) or (S_PID = 1458) or (S_PID = 1031) or (S_PID = 1038) or (S_PID = 1045) or (S_PID = 1051) or (S_PID = 1068) or (S_PID = 1077) or _

    (S_PID = 1471) or (S_PID = 1077) or (S_PID = 1466) or (S_PID = 1467) or (S_PID = 1327) or (S_PID = 1332) or (S_PID = 1328) or (S_PID = 1001) or _

    (S_PID = 1295) or (S_PID = 1296) Or _

    (Subject = 1005) or (Subject = 1458) or (Subject = 1031) or (Subject = 1038) or (Subject = 1045) or (Subject = 1051) or _

    (Subject = 1068) or (Subject = 1077) or (Subject = 1471) or (Subject = 1077) or (Subject = 1466) or (Subject = 1467) or (Subject = 1327) or (Subject = 1332) _

    or (Subject = 1328) or (Subject = 1001) or (Subject = 1002) or (Subject = 1003) or (Subject = 1295) or (Subject = 1296) then

    IncidentAppType = "Business Applications"

    Else If (S_PID = 1057) or (Subject = 1478) or (Subject = 1057) then

    IncidentAppType = "Instructional Applications"

    End If

    Let me know is there any other logic around this in SSRS.

    -----

    Dhans

  • Dhans (2/12/2009)


    Hi,

    Currently I am migrating Crystal reports to SSRS 2008. I am struggling to covert Crystal rpt formulas like below to SSRS. if {table.Subject Parent ID} in [1005,1458, 1031, 1038, 1045, 1051,

    1068, 1077, 1237, 1466, 1467, 1327, 1332, 1328,1001, 1295, 1296]

    Or

    {table.Seq.Subject} in [1005,1458, 1031, 1038, 1045, 1051,

    1068, 1077, 1471, 1466, 1467, 1327, 1332, 1328,1001, 1002,1003,1295,1296]

    then "Business Applications"

    else If

    {table.Subject Parent ID} = 1057 or {table.Seq.Subject} in [1478,1057]

    then "Instructional Applications"

    My question is, how to convert this to SSRS Expression. ( any nice way?) Help me...

    Regards

    Dhans

    I assume they are using this for a grouping purpose??

    have you try using WHEN....THEN.... for example

    WHEN Subject Parent ID IN ('111','112'..) THEN 'Business Applications'

    ELSE 'Instructional Applications'

    END AS TEMP

    Have a read BOL of the correct syntax because my one might be wrong.

  • Thanks Sun.

    I created a Calculated field in dataset and calling a function in Code behind. This function returns the Type of Incident.

    Let me try with SQL Query it self.(using CASE... WHEN). This option may improve the performance too.

    Dhans.

  • working it out at the SQL DB end is ideal. If that is not possible, then expression below should work.

    =switch(S_PID = 1005 or S_PID = 1458 or S_PID = 1031 or S_PID = 1038 or S_PID = 1045 or S_PID = 1051 or S_PID = 1068 or S_PID = 1077 or

    S_PID = 1471 or S_PID = 1077 or S_PID = 1466 or S_PID = 1467 or S_PID = 1327 or S_PID = 1332 or S_PID = 1328 or S_PID = 1001 or

    S_PID = 1295 or S_PID = 1296 Or Subject = 1005 or Subject = 1458 or Subject = 1031 or Subject = 1038 or Subject = 1045 or Subject = 1051 or

    Subject = 1068 or Subject = 1077 or Subject = 1471 or Subject = 1077 or Subject = 1466 or Subject = 1467 or Subject = 1327 or Subject = 1332

    or Subject = 1328 or Subject = 1001 or Subject = 1002 or Subject = 1003 or Subject = 1295 or Subject = 1296, "Business Applications",

    S_PID = 1057 or Subject = 1478 or Subject = 1057,"Instructional Applications")

    I assume you will rewrite it as Dataset.Fieldname.Value for S_PID and Subject

    View Siva Gurusamy's profile on LinkedIn

    "Software changes. This is a rather obvious statement, but it is a fact that must be ever present in the minds of developers and architects. Although we tend to think of software development as chiefly an engineering exercise, the analogy breaks down very quickly. When was the last time someone asked the designers of the Empire State building to add ten new floors at the bottom, put a pool on the top, and have all of this done before Monday morning? " : Doug Purdy, Microsoft Corporation

  • Would anybody be able to help me with changing this expression to SSRS? The prompts are PERIOD and YEAR for the user.

    Here is the Crystal:

    If {Command.Period} = 1 Then

    (MonthName(10)) & ' ' & cStr(ToNumber({Command.Year})-1, "####") ELSE

    if {Command.Period} = 2 Then

    (MonthName(11)) & ' ' & cStr(ToNumber({Command.Year})-1, "####") ELSE

    If {Command.Period} = 3 Then

    (MonthName(12)) & ' ' & cStr(ToNumber({Command.Year})-1, "####") ELSE

    if {Command.Period} = 4 Then

    (MonthName(1)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 5 Then

    (MonthName(2)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 6 Then

    (MonthName(3)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 7 Then

    (MonthName(4)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 8 Then

    (MonthName(5)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 9 Then

    (MonthName(6)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 10 Then

    (MonthName(7)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 11 Then

    (MonthName(8)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 12 Then

    (MonthName(9)) & ' ' & {Command.Year}

  • hi.. dhans.

    this one is general Question..

    why do u want to migrate from crystal report to SSRS report..

    leaving cost is less.. is there any reason for migrating..

    please let me know..

  • kathleen.zak (3/21/2011)


    Would anybody be able to help me with changing this expression to SSRS? The prompts are PERIOD and YEAR for the user.

    Here is the Crystal:

    If {Command.Period} = 1 Then

    (MonthName(10)) & ' ' & cStr(ToNumber({Command.Year})-1, "####") ELSE

    if {Command.Period} = 2 Then

    (MonthName(11)) & ' ' & cStr(ToNumber({Command.Year})-1, "####") ELSE

    If {Command.Period} = 3 Then

    (MonthName(12)) & ' ' & cStr(ToNumber({Command.Year})-1, "####") ELSE

    if {Command.Period} = 4 Then

    (MonthName(1)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 5 Then

    (MonthName(2)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 6 Then

    (MonthName(3)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 7 Then

    (MonthName(4)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 8 Then

    (MonthName(5)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 9 Then

    (MonthName(6)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 10 Then

    (MonthName(7)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 11 Then

    (MonthName(8)) & ' ' & {Command.Year} ELSE

    if {Command.Period} = 12 Then

    (MonthName(9)) & ' ' & {Command.Year}

    Hi kathleen.zak,

    It's usually better to post a new question as a new thread rather than a reply to an old thread, but here's some help.

    The SWITCH function in SSRS will reproduce the if-then logic in your Crystal Reports expression. This function accepts a set of expression/value pairs, evaluates the expressions, and returns the value associated to the first expression that evaluates to TRUE. It looks like this:

    =Switch([expression1], [value1], [expression2], [value2], . . . [expressionN], [valueN])

    So, with this code:

    =Switch(1=0, "NO", 1=1, "YES", 2=2, "WHAT???")

    the function will return the string 'YES' because 1=1 is the first expression that evaluates to TRUE.

    Use the CStr and CInt functions to convert your input parameters to the appropriate data types to perform the comparisons and concatenations. Also, string literals in SSRS expressions must be enclosed in double quotation marks.

    SSRS uses this format to refer to report parameters in expressions: Parameters!YEAR.value

    Here's a short version of what your expression would look like rewritten for SSRS (assuming that the Period parameter is integer data type and the Year parameter is a String data type):

    =Switch(Parameters!Period.value = 1, MonthName(10) & " " & CStr(CInt(Parameters!Year.value)-1), Parameters!Period.value = 2, (MonthName(11)) & " " & CStr(CInt(Parameters!Year)-1), Parameters!Period.value = 3, (MonthName(12)) & " " & CStr(CInt(Parameters!Year.value)-1))

    So, if the user selects Period = 2 and Year = 2010, the function will return the string 'November 2009'.

    Hope that helps!

    Jason Wolfkill

  • @vinayak.v

    I was thinking the same when I migrate to SSRS, but there are lot of advantages in SSRS 2008/R2 than Crystal..

    Expression is far better than crystal

    SSRS report engine is much faster that Crystalengine for data process... I compared the same report in both platforms.

    Using the code behind you can use Vb or C# .net short functions/subs for expressions (the one Kathleen trying to do)..

    Embedding to platforms is easy and Report security.

    Reporting webservice enables applications to show the report in their pages by report viewer/pdf/etc...

    There may be lot.. simply google to get the answer.. :hehe:

  • @ Kathleen

    You can do like wolfkillj said,

    Or try this..

    Since the period is starts from October

    Write expression like below,

    = iif(Parameters!Period.value <= 3, MonthName(Parameters!Period.value + 9) + " " + Parameters!Year.Value-1.ToString,

    MonthName(Parameters!Period.value -3) + " " + Parameters!Years.value.ToString)

    Replace Parameters!Period.Value with Fields!Period.value if you are using Dataset Fields, same for Parameters!Year.Value

    Hope this one solves the problem..:-)

  • Thanks! It works Great!

  • If you are converting a bunch of crystal reports to RDL you should look at CrystalConversions.com

    It converted your if/then/else to:

    Switch(Fields!PERIOD.Value = 1, (MonthName(10)) & " " & Format(Fields!YEAR.Value-1, "####"),

    Fields!PERIOD.Value = 2, (MonthName(11)) & " " & Format(Fields!YEAR.Value-1, "####"),

    Fields!PERIOD.Value = 3, (MonthName(12)) & " " & Format(Fields!YEAR.Value-1, "####"),

    Fields!PERIOD.Value = 4, (MonthName(1)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 5, (MonthName(2)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 6, (MonthName(3)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 7, (MonthName(4)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 8, (MonthName(5)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 9, (MonthName(6)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 10, (MonthName(7)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 11, (MonthName(8)) & " " & Fields!YEAR.Value,

    Fields!PERIOD.Value = 12, (MonthName(9)) & " " & Fields!YEAR.Value)

    However it just did a direct mechanical conversion, the previous poster had a better solution by using the month as an index into Monthname. You could also use modulo arithmetic to do something similar.

    E.g. MonthName((Fields!PERIOD.Value+9) Mod 12)

  • You may take a look at Crystal Migration Services. Formulas like this can be perfectly converted.

    The solution is there. Just have a try and compare each other and then you can easily find which is the best choice for you.

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply