Hello I am working in crystal and am wanting to add a formula field called Group 1, and want to use SQL query like this:
CASE '{?Group 1}'
WHEN 'Location' THEN (CASE WHEN COALESCE(TABLE_NAME_1.COLUMN_NAME_1, TABLE_NAME_1.COLUMN_NAME_2) IS NULL THEN '*Unspecified Location'
WHEN TABLE_NAME_2.COLUMN_NAME_1 IS NULL THEN CONCAT('*Unknown Location', CONCAT(' [',CONCAT(COALESCE(TABLE_NAME_1.COLUMN_NAME_1, TABLE_NAME_1.COLUMN_NAME_2),']')))
WHEN TABLE_NAME_2.COLUMN_NAME_2 IS NULL THEN CONCAT('*Unnamed Location', CONCAT(' [',CONCAT(TABLE_NAME_2.COLUMN_NAME_1,']')))
ELSE TABLE_NAME_2.COLUMN_NAME_2 END)
ELSE NULL END GROUP_1
Not entirely sure how this translates into crystal. Any help would be great.
Thank you
Ok I reworked the formula and came up with:
IF {?Group1} = "Location" THEN
IF ISNULL({TABLE_NAME_1.COLUMN_NAME_1}) THEN "*Unspecified Location" ELSE
IF ISNULL({TABLE_NAME_1.COLUMN_NAME_2}) THEN "*Unspecified Location" ELSE
IF ISNULL({TABLE_NAME_2.COLUMN_NAME_1}) THEN "*Unknown Location" ELSE
IF ISNULL({TABLE_NAME_2.COLUMN_NAME_2}) THEN "*Unnamed Location"
ELSE {TABLE_NAME_2.COLUMN_NAME_2}
I think this might work. Would you agree or is there a better way?
your conversion is almost correct need some changes check below.
IF {?Group1} = "Location" THEN
(
IF (ISNULL({TABLE_NAME_1.COLUMN_NAME_1}) or ISNULL({TABLE_NAME_1.COLUMN_NAME_2}))
THEN "*Unspecified Location"
ELSE IF ISNULL({TABLE_NAME_2.COLUMN_NAME_1})
THEN "*Unknown Location " &IIF((ISNULL({TABLE_NAME_1.COLUMN_NAME_1}) or ISNULL({TABLE_NAME_1.COLUMN_NAME_2})),{TABLE_NAME_1.COLUMN_NAME_1},{TABLE_NAME_1.COLUMN_NAME_2})
ELSE IF ISNULL({TABLE_NAME_2.COLUMN_NAME_2})
THEN "*Unnamed Location " & {TABLE_NAME_2.COLUMN_NAME_1}
)
ELSE {TABLE_NAME_2.COLUMN_NAME_2}
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})
)
Can anyone let me know how to write a CASE STATEMENT like in SQL but in a Jaspersoft 6 report? More precisely inside the expression editor.
For example:
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END
You need to use a ternary operator like below:
$F{variable_1}.equals("R") == true ? 'Road' : "Else not for Sale"
Well you can't use case directly but having if else condition within another if else condition will give the solution.
Here's an example below where the switch-case functionality is achieved through multiple if else conditions
( $F{FIELDV}.equals("ab") ? "aaaa" :
( $F{FIELDV}.equals("bc") ? "bbbb" :
( $F{FIELDV}.equals("de") ? "cccc" : ""
)))
Hi there I'm making an access database, and I can't figure out how to do one particular thing.
I've got a form with two text boxes: MovieID and CustomerID. I also have three separate tables: MovieList, CustomerInfo and HireHistory. What I need is so that when I enter a MovieID and CustomerID into the given boxes then press my button HireButton, it edits that specific MovieID's LastHireDate to Today(), edits that specific CustomerID's LastHireDate to Today(), and then in my HireForm (which has the CustomerID's in the first row) it adds a new record below the CustomerID in the form of: MovieID " on " Today()
Also, I need to make it so that it checks that MovieID's genre and if it's R16 or R18, then it checks whether the customer is older than 16 or 18 today, and if not then it comes up with an error box. I know how to do the checking whether they are older than 16 or 18, but not the error box.
I know that's a lot of text, so I'll just write what's in my brain (how I see the code should be) so it will be easier to see what I want to do.
IF MovieID.Rating = 'R16' OR 'R18'
THEN IF CustomerID.[Date(Year(DOB)+16,Month(DOB),(Day(DOB))] > Today()
THEN DISPLAY Msgbox = "Sorry, too young"
ELSE SET CustomerID.LastHireDate = Today()
SET MovieID.LastHireDate = Today()
ADDRECORD in HireHistory for that CustomerID to (MovieID & " on " & Today())
ELSE SET CustomerID.LastHireDate = Today()
SET MovieID.LastHireDate = Today()
ADDRECORD in HireHistory for that CustomerID to (MovieID & " on " & Today())
Does that explain it a bit better? Thanks in advance for your help! :)
so here How I would do this. You first have to create a recordset for each of those table.
For the age I would use this function. : http://www.fmsinc.com/MicrosoftAccess/modules/examples/AgeCalculation.asp
customerBirth = yourCode to get the date
If MovieID.Rating = 'R16' OR 'R18' then
If AgeYears(customerBirth) < 16 then
msgbox("Sorry, too young")
else
MyCustomerRecordSet("LastHireDate") = now
MyMovieRecordSet("LastHireDate") = now
MyHireRecorset.AddNew
MyHireRecorset("I don't know what your trying to do here")
MyHireRecorset.Update
end if
Else
MyCustomerRecordSet("LastHireDate") = now
MyMovieRecordSet("LastHireDate") = now
MyHireRecorset.AddNew
MyHireRecorset("I don't know what your trying to do here")
End if
If you have any question just ask.
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'm trying to create a new field and then later on in my program reference that new field within a case statement, but I can't seem to get the syntax right - my error message says there's an error near the '='.
Here's my code:
declare #source_sys_obligation_id varchar(40);
if facility_utilization in ('F')
set source_sys_obligation_id = source_sys_facility_id
else set source_sys_obligation_id = source_sys_utilization_num;
select
source_sys_utilization_num
,source_sys_id
,facility_utilization
,case when source_sys_id in ('AFSEAST','AFSLSAL','DFBDOM','ACBS')
then right('000000000000000' + substring(source_sys_obligation_id,6,10),16)
when source_sys_id in ('MLSTLEND')
then right('000000000000000' + left(source_sys_obligation_id,15),16)
else '' end as No
from BridgeUnderwrite.dbo.t_sag_pimsc1
where source_sys_id in ('AFSEAST','AFSLSAL','DFBDOM','ACBS','MLSTLEND')
order by source_sys_id
;
The error is in reference to the set statements. They should look like:
if facility_utilization in ('F')
set #source_sys_obligation_id = source_sys_facility_id
else
set #source_sys_obligation_id = source_sys_utilization_num;
That ought to do it :) . . . however, source_sys_facility_id and source_sys_utilization_num are most likely going to be your next issues . . . are they variables (or perhaps parameters passed in) as well?
The '#' is part of the name. All T-SQL variable names or procedure parameters have to begin with this character (I assume the reason is so they are easy to discern from table and column names). So you probably need to say set #source_sys_obligation_id ... instead of set source_sys_obligation_id ....
What you want and what you can have are not the same! You cannot create a field in a select stament and then reference it in the same select statment in a case. Your code makes no sense at all and indcates a severe lack of understanding of how variables work.
declare #source_sys_obligation_id varchar(40);
if facility_utilization in ('F')
set source_sys_obligation_id = source_sys_facility_id
else set source_sys_obligation_id = source_sys_utilization_num;
This does not add columns to a select nor would it even populate anything even adding the #sign as some others have suggested because you do not have a select here. Further a variable can only have one value, not a different value per record. So scrap this whole approach. What you really need is a derived table or a CTE. You could also simply embed the first case in the second case. Something like this might get waht you are asking for:
SELECT a.source_sys_utilization_num
,a.source_sys_id
,a.facility_utilization
,CASE WHEN a.source_sys_id in ('AFSEAST','AFSLSAL','DFBDOM','ACBS')
THEN RIGHT('000000000000000' + SUBSTRING(a.source_sys_obligation_id,6,10),16)
WHEN a.source_sys_id in ('MLSTLEND')
THEN RIGHT('000000000000000' + LEFT(a.source_sys_obligation_id,15),16)
ELSE '' END AS [No]
FROM
(SELECT
source_sys_utilization_num
,source_sys_id
,facility_utilization
,CASE WHEN facility_utilization = 'F' THEN source_sys_facility_id
ELSE source_sys_utilization_num END AS source_sys_obligation_id
FROM BridgeUnderwrite.dbo.t_sag_pimsc1
WHERE source_sys_id in ('AFSEAST','AFSLSAL','DFBDOM','ACBS','MLSTLEND')) a
ORDER BY source_sys_id
Too busy to write the other versions. Maybe someone else will supply.