I got an error with the below SQL I wrote in ACCESS, where is my mistake? I've other when statements to add
UPDATE daily_inventory t0
SET
t0.Type = CASE
WHEN t0.[item number] LIKE "*-FG-*"
THEN "Float"
END
MS Access won't support CASE expression use IIF() instead :
UPDATE daily_inventory AS t0
SET t0.[Type] = IIF(t0.[item number] LIKE "*-FG-*", "Float", '<whatever>')
Related
I'm trying to take the following sql case statement and convert it to Access 2010 as a calculation for a column. I've looked at the IIF statements but have received errors trying to sort it out. Thank you for any help.
case
when left(Tiers,4) = 'Tier' and isnumeric(right((left(Tiers,7)),2)) = 1 then right((left(Tiers,7)),2)
when left(Tiers,4) = 'Tier' and isnumeric(right((left(Tiers,7)),2)) = 0 then right((left(Tiers,6)),1)
else Tiers
end
;
you can only use Case statements in access in VBA Code.
and iif should work as well in access
like this
iif(left(Tiers,4) ='Tire',iif(isnumeric(right((left(Tiers,7)),2)) = 1,right((left(Tiers,7)),2),right((left(Tiers,6)),1)), Tires)
You can use IIF() as you mentioned and it will likely be a pain. There is also SWITCH function available which will likely make it easier for you to convert your case statement instead of nested IIF()s
Switch( expr-1, value-1 [, expr-2, value-2 ] … [, expr-n, value-n ] )
https://support.office.com/en-us/article/Switch-Function-d750c10d-0c8e-444c-9e63-f47504f9e379
This is a duplicate question of:
Case expressions in Access.
I'm trying to translate this nested if statement into set analysis expression.
=Sum(if(Project=96,WorkTime*39.273,if(Project=92 and WorkType<>65,WorkTime*32.426,WorkTime*42.251)))
This is what I've done
=Sum({$<Project={96}>}WorkTime*39.273) or Sum({$<Project = {96}, WorkType -={65}>} WorkTime*32.426) or Sum({$<Project = {96}>} WorkTime*42.251)
I get an error near WorkType -= {65}, the problem is the operator. I've tried it even with <>, still an error.
If you just want to ignore some filters you can use your if expression combined with set analysis to ignore those fields like:
=Sum({<Field1_to_ignore = , Field2_to_ignore = >}if(Project=96,WorkTime*39.273,if(Project=92 and WorkType<>65,WorkTime*32.426,WorkTime*42.251)))
I'm getting 00923. 00000 "FROM keyword not found where expected" error while using case. can you help me with multiple cases. How to use them and how to resolve below case
SELECT WorkflowHistory.*,
Reason.Reason,
ApprovalType.ApprovalType
CASE
WHEN NVL(APPROVALTYPE,'')=''
THEN 'APPROVALTYPE' = XPURPOSEFORREJECTION
END
CASE
WHEN NVL(daction,'')='sendTo'
THEN 'daction' = 'Approve'
END
FROM WorkflowHistory WorkflowHistory,
Reason Reason,
ApprovalType ApprovalType
WHERE UPPER(dDocName) = UPPER('D_1238777')
AND xPurposeForSubmission = Reason.ReasonID(+)
You need to add commas to separate your case expressions, and add optional field names. The assignment syntax needs to be changed like this:
SELECT WorkflowHistory.*,
Reason.Reason,
ApprovalType.ApprovalType
CASE
WHEN APPROVALTYPE IS NULL
THEN XPURPOSEFORREJECTION
END AS APPROVALTYPE,
CASE
WHEN NVL(daction,'')='sendTo'
THEN 'Approve'
END AS daction
FROM WorkflowHistory WorkflowHistory,
Reason Reason,
ApprovalType ApprovalType
WHERE UPPER(dDocName) = UPPER('D_1238777')
AND xPurposeForSubmission = Reason.ReasonID(+)
Your query appears to be missing join criteria for the ApprovalType table. Also consider switching to ANSI joins from Oracle-specific (+) syntax.
I am attempting in Access to show some data in a listbox, but only data which meets a certain condition should be displayed, however my SQL is flagging the error;
Syntax Error (missing operator) in query expression tblItem.[Status] WHERE (tblItem.[Status] = 'Unassigned
Here is my full query
`SELECT tblItem.[Serial Number],
tblItem.[Item Description],
tblItem.[Model],
tblItem.[Status]
WHERE (tblItem.[Status] = 'Unassigned') FROM tblItem;`
Where am i going wrong?
try this
SELECT tblItem.[Serial Number],
tblItem.[Item Description],
tblItem.[Model],
tblItem.[Status]
FROM tblItem
WHERE tblItem.[Status] = 'Unassigned'
I think You have misplaced the from and where clause
Remember the syntax for select:
SELECT ... FROM ... WHERE ... ORDER BY
My query is as follows :
I have written in access can anyone pls help how can I convert it into sql query I am getting an error near IIF condition.
SELECT #NT_VAR_STEP_1_1.SYS_ID, #NT_VAR_STEP_1_1.NODE, #NT_VAR_STEP_1_1.TEMP_ID,
#NT_VAR_STEP_1_1.EQUIP_TYPE, #NT_VAR_STEP_1_1.EQ_ID,
#NT_VAR_STEP_1_1.VAR_ID, #NT_VAR_STEP_1_1.NODE AS VAR_SET,
#NT_VAR_STEP_1_1.VAR_NAME, IIf([#NT_VAR_STEP_1_1]![VAR_SUBSET]=‘SELF’,
[#NT_VAR_STEP_1_1]![NODE],[#NT_VAR_STEP_1_1]![VAR_SUBSET]) AS VAR_SUBSET,
IIf([#NT_VAR_STEP_1_1]![EQUIP_TYPE]=‘SOURCE’,’PARAMVAR’,’VAR’) AS CALC_VAR_TYPE,
#NT_VAR_STEP_1_1.VAR_DATA_TYPE AS DATA_TYPE, #NT_VAR_STEP_1_1.DOF,
#NT_VAR_STEP_1_1.RETAIN, #NT_VAR_STEP_1_1.COEFF_OBJECT,
#NT_VAR_STEP_1_1.COEFF_VAR_SET, #NT_VAR_STEP_1_1.COEFF_VAR_TYPE,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBSET, #NT_VAR_STEP_1_1.COEFF_VAR_NAME,
#NT_VAR_STEP_1_1.OPERAND, #NT_VAR_STEP_1_1.SIGN,
#NT_VAR_STEP_1_1.VAR_TP_OFFSET, #NT_VAR_STEP_1_1.COEFF_TP_OFFSET,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBTYE INTO #OT_VAR_STEP_1_1_1
FROM #NT_VAR_STEP_1_1
GROUP BY #NT_VAR_STEP_1_1.SYS_ID, #NT_VAR_STEP_1_1.TEMP_ID,
#NT_VAR_STEP_1_1.EQUIP_TYPE, #NT_VAR_STEP_1_1.EQ_ID,
#NT_VAR_STEP_1_1.VAR_ID, #NT_VAR_STEP_1_1.NODE,
#NT_VAR_STEP_1_1.VAR_NAME, IIf([#NT_VAR_STEP_1_1]![VAR_SUBSET]=‘SELF’,
[#NT_VAR_STEP_1_1]![NODE],[#NT_VAR_STEP_1_1]![VAR_SUBSET]),
IIf([#NT_VAR_STEP_1_1]![EQUIP_TYPE]=‘SOURCE’,’PARAMVAR’,’VAR’),
#NT_VAR_STEP_1_1.VAR_DATA_TYPE, #NT_VAR_STEP_1_1.DOF,
#NT_VAR_STEP_1_1.RETAIN, #NT_VAR_STEP_1_1.COEFF_OBJECT,
#NT_VAR_STEP_1_1.COEFF_VAR_SET, #NT_VAR_STEP_1_1.COEFF_VAR_TYPE,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBSET, #NT_VAR_STEP_1_1.COEFF_VAR_NAME,
#NT_VAR_STEP_1_1.OPERAND, #NT_VAR_STEP_1_1.SIGN,
#NT_VAR_STEP_1_1.VAR_TP_OFFSET, #NT_VAR_STEP_1_1.COEFF_TP_OFFSET,
#NT_VAR_STEP_1_1.COEFF_VAR_SUBTYE, #NT_VAR_STEP_1_1.NODE
HAVING (((#NT_VAR_STEP_1_1.EQUIP_TYPE)<>‘COST_NODE’));
Convert this line:
IIf([#NT_VAR_STEP_1_1]![EQUIP_TYPE]=‘SOURCE’,’PARAMVAR’,’VAR’) AS CALC_VAR_TYPE
to this:
CASE WHEN [#NT_VAR_STEP_1_1].[EQUIP_TYPE]='SOURCE'
THEN 'PARAMVAR'
ELSE 'VAR'
END CALC_VAR_TYPE
And then use the same in your GROUP BY clause, but without the column alias:
CASE WHEN [#NT_VAR_STEP_1_1].[EQUIP_TYPE]='SOURCE'
THEN 'PARAMVAR'
ELSE 'VAR'
END
I will assume you're going to SQL Server (T-SQL). T-SQL does not support IIF, you will need to use CASE instead.