Getting this error - ORA-00936: missing expression - sql

I am new to SQL and trying to use an if statement equivalent in order to get the value in SQL.
After running this report I am getting the error "ORA-00936: missing expression"
CASE WHEN (select Sum(MONTANT) from fraisExterne where matching=fm.id and statut=3) IS NULL
THEN select sum(MONTANT) from fraisExterne where matching=fm.id
ELSE Select sum (MONTANTHTBROKER) from fraismatching where matching=fm.id
End End as "BROKER AMOUNT"
Please let us know if you can help me with it

You have a extra END key word at the end of your case statement. You also need to put your select query into ().
Try this:
SELECT
CASE
WHEN (select Sum(MONTANT) from fraisExterne where matching=fm.id and statut=3) IS NULL THEN (select sum(MONTANT) from fraisExterne where matching=fm.id)
ELSE (Select sum (MONTANTHTBROKER) from fraismatching where matching=fm.id)
End AS BROKER_AMOUNT
I hope this helps and welcome to StackOverflow. If you find this answer or any other answer solves your problem please mark it as the solution. This will help the community and fellow programmers who run into the same problem in the future. Thanks.

Related

Converting Access Syntax into SQL Syntax

I am trying to convert the below into from an Access Database Syntax to sql query syntax using Case-When-Then etc. Can someone help me?
SpreadType: IIf([mv_Loan_Ext1]![LoanPurposeTypeCode] In ("008","080"),"QRLF-" & IIf([FAReceivesPatronage]=0,"NPAT","PAT"),IIf([SecDistrictIndustryCode]="999","Non-QRLF",IIf([PriDistrictIndustryCode]="999","RHL",IIf([mv_Loan_Ext1]![LoanPurposeTypeCode]+0 Between 1 And 7,"Other home",IIf([FANoteIsParticipationPurchased]=1,IIf([mv_FANote]![BranchNbr]="092","100% GP","PP"),IIf([PatronagePoolCode]="14","FCE",IIf([YBSAgStart]<>"No" Or IIf(Trim([AgGrow_NoOperator]) Is Null,0,IIf(Trim([AgGrow_NoOperator])="" Or Trim([AgGrow_NoOperator])="No",0,1))+IIf(Trim([AgNiche]) Is Null,0,IIf(Trim([AgNiche])="" Or Trim([AgNiche])="No",0,1))+IIf(Trim([AgGrowOperator]) Is Null,0,IIf(Trim([AgGrowOperator])="" Or Trim([AgGrowOperator])="No",0,1))>0,"YBS AgStart",IIf([GrainInventoryLoan]="Yes","Grain Inventory",IIf([COVID19] Like "SBA*","PPP",IIf(IIf([FarmTypeAbbr]="",IIf([FCALoanTypeAbbr]="PRIT","FL",IIf([FCALoanTypeAbbr]="REMG","FL","")),[FarmTypeAbbr])<>"FL","General non-farmer","Core farmer loans"))))))))))
You have to rewrite your query like this. You just have too many embed (). This is little mess.
select
case when [mv_Loan_Ext1].[LoanPurposeTypeCode] in ('008', '080') then 'QRLF-' + case FAReceivesPatronage when 0 then 'NPAT' else 'PAT' end
when [SecDistrictIndustryCode] = '999' THEN 'Non-QRLF'
when ...
end

SQL query using if else

My SQL code looks like this:
SELECT
Scores.PupilId, Scores.BoysName, Scores.FormGroup,
IF (Scores.FormGroup = "10SB", "Great", "ok")
FROM
Scores
I get this message
no such function: if: SELECT Scores.PupilId, Scores.BoysName, Scores.FormGroup,
if(Scores.FormGroup="10SB","Great","ok")
FROM Scores
This is flat file database
Can anyone please help me understand why I am getting a message?
The correct ANSI-standard conditional expression in SQL is the case expression:
SELECT Scores.PupilId, Scores.BoysName, Scores.FormGroup,
(CASE WHEN Scores.FormGroup = '10SB' THEN 'Great' ELSE 'ok' END)
FROM Scores ;

Cognos Analytics: QE-DEF-0459 on a CASE WHEN expression

I am trying to create a new data item based on certain conditions. I did run across a couple of threads regarding this very issue, but I either don't know what syntax I need or I can't find where my syntax error is located. I am receiving a parsing error: QE-DEF-0459, QE-DEF-0260, and QE-DEF-0261
for the below code.
CASE
WHEN [Shipping].[Wave PARM].[MISC_STAT_CODE_2] =2 AND [ASRS_Lines] IS NOT NULL
THEN 'Sent'
WHEN [Shipping].[Wave PARM].[MISC_STAT_CODE_2] !=2 AND [ASRS_Lines] IS NOT NULL
THEN 'Not Sent'
ELSE NULL
END
I can't seem to figure out how to correct this error and any help would be greatly appreciated.
I have also tried...
IF [Shipping].[Wave PARM].[MISC_STAT_CODE_2] = 2 AND [ASRS_Lines] IS NOT NULL
THEN 'Sent'
ELSE IF [Shipping].[Wave PARM].[MISC_STAT_CODE_2] != 2 AND [ASRS_Lines] IS NOT NULL
THEN 'Not Sent'
ELSE NULL
END
Thank you in advance.
There is only one item that Cognos may take issue with there. Try <> instead of !=.
If that doesn't fix the problem, try deleting that data item and validating the report. If it still fails, that data item is not where the problem is.

SQL Syntax Error

I'm getting an incorrect syntax error when I try to execute this query in t-sql. I'd appreciate any help - I believe the issue is on, or around the ROUND statement.
SELECT
EMPL.employeeid as KEmplID,
EMPL.PERSONNUM as EmployeeNumber,
EMPL.PERSONFULLNAME as FullName,
....
FROM
VP_EMPLOYEE as EMPL,
VP_PERSON as PRSN,
(
SELECT
TLS.employeeid as EMPLID,
TLS.applydate as APPLYDATE,
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60,1)) AS ElapsedHrs
FROM
VP_TOTALS as TLS,
VP_PAYCODE as PAYCODE
....
I am just not quite sure where my issue stems - again, I think it is the round statement but I could be wrong. I will appreciate any and all help - or suggestions - to make this more efficient or help with the rounding, conversion and sum of the data.
Incorrect:
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60,1)) AS ElapsedHrs
Corrected (parenthesis placement):
ROUND((SUM(CONVERT(FLOAT,TLS.timeinseconds)) /60/60),1) AS ElapsedHrs
^

Problems with SQL syntax DATEADD

SELECT hd.holiday_code,
hd.holiday_duration,
hdep.departure_date AS 'Start Date',
Dateadd(day, hd.holiday_duration, hdep.departure_date) AS 'End Date'
FROM holiday_details hd
INNER JOIN holiday_departure hdep
ON hd.holiday_code = hdep.holiday_code
Well i've been trying to get this specific code ^ to work, but i cant figure out the dateadd syntax. It looks right from what i have research on the googles, but i always get the error ORA-00923: FROM keyword not found where expected
This is usually caused my some minor error on my part, but i cant find it after looking for about 20 minutes. Can anyone point out the error that is probably staring me in the face
Simply add the number of days with a numeric value. Another problem with your syntax is in 'Start Date' and 'End Date'; replace single quotes with double quotes. Change your query for something like this:
SELECT hd.holiday_code,
hd.holiday_duration,
hdep.departure_date AS "Start Date",
hdep.departure_date + hd.holiday_duration AS "End Date"
FROM holiday_details hd
INNER JOIN holiday_departure hdep
ON hd.holiday_code = hdep.holiday_code
Hope it helps.