How can I re-write the following Formula from Crystal Reports in SSRS
select {spAR6100b_allcompanies;1.artyp}
case 'BCS','CIG','HUM','INA','INS','MNG','PHC','SEC','SPC','TRI','UHC','WMD' : 'Primary'
case 'COI','ICO','INP','MCO','COI' : 'Secondary'
default: ''
SSRS expressions generally don't work very well for IN comparisons.
There are a few options.
Use a Switch and a set of linked Or statements:
=Switch(Fields!arTyp.Value = "BCS" or Fields!arTyp.Value = "BCS" or Fields!arTyp.Value = "HUM", "Primary"
, Fields!arTyp.Value = "COI" or Fields!arTyp.Value = "ICO", "Secondary"
, True, "")
I've only included a few of your cases and you can see it's already long - you would need to add as many values as you need.
With string matches you can streamline this a bit by checking if the field value is in a string of match values:
=Switch(InStr(",BCS,CIG,HUM,", "," & Fields!arTyp.Value & ",") > 0, "Primary"
, InStr(",COI,ICO,INP,", "," & Fields!arTyp.Value & ",") > 0, "Secondary"
, True, "")
We wrap everything in commas to prevent false positives on part matches. Again, add all the required values into the string list of match values.
Finally, you could use custom code for this comparison and move the comparison to a VB.NET type function embedded in the report.
Related
So, I'm much more familiar with Transact-SQL than I am with Crystal formulas. What I would like to do is convert something like the following SQL where clause to be used in Crystal to conditionally suppress a section:
.
.
.
AND (osAddressUse.Description <> 'Conservator Address'
OR (
ISNULL(bcDocumentDetail.PrimaryStreet,'') = ISNULL(osaddress.PrimaryStreet,'')
AND
ISNULL(bcDocumentDetail.SecondaryStreet,'') = ISNULL(bcDocumentDetail.SecondaryStreet,'')
)
)
.
.
.
Basically, the section should only display if the osAddressUse.Description = "Conservator Address" OR both the Primary Street and Secondary Street within both tables bcDocumentDetail and osAddress are not identical.
What I came up with so far is the following, but it doesn't work 100% of the time:
{osAddressUse.Description} <> "Conservator Address"
OR
( {bcDocumentDetail.PrimaryStreet} = {osAddress.PrimaryStreet}
AND
{bcDocumentDetail.SecondaryStreet} = {osAddress.SecondaryStreet} )
There are some situations where the data in these fields can either be NULL or "". If it's a NULL value, I want it converted to "", that way, they technically match, and the section will be suppressed.
Nevermind. I was able to figure it out:
TRIM ({osAddressUse.Description}) <> "Conservator Address"
OR
(
(IF ISNULL({osAddress.PrimaryStreet}) THEN "" ELSE {osAddress.PrimaryStreet})
= (IF ISNULL({bcDocumentDetail.PrimaryStreet}) THEN "" ELSE {osAddress.PrimaryStreet})
AND
(IF ISNULL({osAddress.SecondaryStreet}) THEN "" ELSE {osAddress.SecondaryStreet})
= (IF ISNULL({bcDocumentDetail.SecondaryStreet}) THEN "" ELSE {osAddress.SecondaryStreet})
)
I'm working on a report in Crystal Reports XI that allows someone to filter help desk tickets using a number of optional dynamic parameters. If I make a selection for each parameter it returns the expected results, but if I leave out any of the parameters it doesn't return anything and when I look at the SQL query it says, "No SQL Query is used because the record selection formula returns no records." I currently have the following code for Record Selection:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
)
and
If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
)
and
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
)
and
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
)
To me, this seems like it should work and if I leave out the If statement to verify the parameters have values I get an error so it seems like the HasValue is working properly. Any ideas?
Your problem stems from not explicitly handling the optional parameter configurations. It's easy to run into this problem when using if-statements in the record selection formula. Instead, explicitly handle the cases where the parameters DO and DO NOT have values. Something like this:
...
(not(hasvalue({?Group})) or {Groups.Code}={?Group})
and
(not(hasvalue({?Category})) or {Incident.Subject Description} = {?Category})
and
(not(hasvalue({?Staff})) or {Incident_Details.Login ID} = {?Staff} )
and
(not(hasvalue({?Community})) or {Incident.Company Name} = {?Community})
Doing it this way effectively tells CR to just ignore the parameter if is doesn't have a value, otherwise select records based on what was entered in those parameters.
The Record Selection formula indicates whether a record must be used, or not, by returning true or false. With that in mind, if some value is informed, the formula must return True if it meets some criteria. If nothing is informed on the filter, the formula must always return True.
Try something like this:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
(If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
) else
(True))
and
(If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
) else
(True))
and (
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
) else
(True))
and (
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
) else
(True))
I have a text column which holds a json with very long values - actually HTML code.
{"first_key" : "a very long html", "second_key" : "another very long html"}
How can I easily delete the second_key and its vale?
You could use regex_replace, and hope that the second html doesn't contain a } character:
update MY_TABLE set text_column = regex_replace(text_column, ', "second_key": ".*\}"', '')
where my_column_id = '<whatever>';
You will have to tweak your regex to make this work. You can test it by doing a select with the same expression to see what you get.
I have a Crystal Report which has two paramaters: {?EmailVerifyStatus} and {?Company}. I want it so that when the two paramaters are blank the report gets all the records.
Here is my current code:
(if {?EmailVerifyStatus}='Y' THEN {PREH.udEmailVerify}='Y'
ELSE IF {?EmailVerifyStatus}='N' THEN {PREH.udEmailVerify}='N'
ELSE 1=1)
and
(if {?Company} <> '0' then not (IF "," & ToText({PREH.PRCo},0,'') & "," IN "," & {?Company} & "," THEN 0=1 ELSE 1=1) else 1=1 )
But, it is only returning the records with a 'Y' value.
You have to check if parameters have set a value with the hasvalue() function. Then you can do this:
(not(hasvalue({?EmailVerifyStatus})) or {PREH.udEmailVerify} = {?EmailVerifyStatus}) and
(not(hasvalue({?PRCo})) or {PREH.Co} = {?Company})
I dont understand your second condition ...
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)