In MS-Access 2007, I have a table, [Test_Master] where I have a field [DT_REPORT]. I want to update [Test_Norm_Due] by 2 months if field [Size] = "small". If the field "Size" = "Med." then by 3 months. I create below query but it is throwing Syntax error. Can someone help.
UPDATE Test_Master
SET Test_Master.Test_Norm_Due =
IIF((([Test_Master]![Size]="small")), DateAdd(("m",2,[Test_Master]![DT_REPORT]))),
IIF((([Test_Master]![Size]="med.")), DateAdd(("m",3,[Test_Master]![DT_REPORT])));
I believe you have a problem with your parentheses - try nesting them using an external Text editor (like notepad++) for greater visibility - also, you are using extra parentheses that are getting in your way, try simplifying; and you're missing one final condition - what should happen with Test_Norm_Due when Size is neither "small" nor "med."
Note that syntax for IIF is:
IIF (condition, value if true, value if false).
You are nesting IIFs, so you should have something like:
IIF (condition, value if true, IIF(other condition, value if true, value if false))
Try something like this (I broke it in multiple lines just to try to make it more visible for you).
UPDATE Test_Master SET Test_Master.Test_Norm_Due =
IIF (([Test_Master]![Size]="small"),
DateAdd("m",2,[Test_Master]![DT_REPORT]),
IIF (([Test_Master]![Size]="med."),
DateAdd("m",3,[Test_Master]![DT_REPORT]),
{missing value - What happens if it's neither "small" nor "med."} ));
Related
I'm working on a search form based off a single table. I'm working primarily in the query design view. I'd like to have a checkbox on the form so if it is checked (true) it will only return records where the setID is Null. If unchecked (false) it will return all records regardless of if there is a value in setID or not. Looking for a bit of help writing the iif statement (I'm very, very new to this).
source table: Inventory
field: setID
form: frmSearchInventory
form control: ckExcludeSet
iif(Forms!frmSearchInventory!ckExcludeSets = true, Inventory.SetID is Null, Inventory.SetID is not Null)
Close? Also, in the query design view, do I need anything additional in the criteria row? Many thanks!
For a dynamic query, calculate a field that returns SetID or a value in lieu of null: Nz(SetID, "N")
Then criteria under that calculated field:
LIKE IIf(Forms!frmSearchInventory!ckExcludeSets, "N", "*")
An unbound checkbox can be set for triple state. Make sure yours allows only True or False, never Null - set TripleState property to No. Set DefaultValue property to either True or False.
I have a query that filters based on a boolean value on a form (Task Archived). The boolean value is stored as a long in the underlying table (only 0 and -1 are allowed).
I wanted to write a query that would either show only those records that are false (records not archived) or all records.
I would have expected the follwing query to work, but it does not... it returns only those records for which the archive field is set to True (-1):
SELECT tbl_Tasks.TaskID, tbl_Tasks.TArchive
FROM tbl_Tasks
WHERE (((tbl_Tasks.TArchive)=
IIf([Forms]![frm_Activity]![txtArchivedTaskDisplay]=0,False,
(tbl_Tasks.TArchive)=0 Or (tbl_Tasks.TArchive)=-1)));
The query below, which I would expect to show only those records that are True, in fact returns all records:
SELECT tbl_Tasks.TaskID, tbl_Tasks.TArchive
FROM tbl_Tasks
WHERE (((tbl_Tasks.TArchive)=
IIf([Forms]![frm_Activity]![txtArchivedTaskDisplay]=0,False,
(tbl_Tasks.TArchive)<>0)));
Why is this? What logic is access follwing here?
You cannot put SQL where condition within IIF. Anything within IIF will be evaluated if possible. Since you only have 0 or -1 below evaluation will always be true.
((tbl_Tasks.TArchive)=0 Or (tbl_Tasks.TArchive)=-1) => true
that's why you are only seeing TArchive = true
You could try something like this for your first query:
WHERE
tbl_Tasks.TArchive **<** IIf(displayArchivedOnly,0,1);
for the second one:
WHERE
tbl_Tasks.TArchive = [Forms]![frm_Activity]![txtArchivedTaskDisplay]
assuming your txtArchivedTaskDisplay holds either true or false value like a toggle button. but again, read more about how iif works.
The data that appears does not match the conditions that have been applied
I implemented SQL code in the Navicat application, and have changed the structure of the code several times but it still doesn't work,
data that is not of ilart condition type
still appears
SELECT SERMAT,ILART,sum(GKSTP) as jumlah
FROM swift_zab_iw39
WHERE ILART='OVH' OR ILART='TST' and SERMAT='024147-000:09052'
GROUP BY ILART,SERMAT
Use IN operator:
WHERE ILART IN('OVH','TST') AND SERMAT = '024147-000:09052'
Add parenthesis to the OR condition in the WHERE clause as:
WHERE (ILART = 'OVH' OR ILART = 'TST') AND SERMAT = '024147-000:09052'
I've just started using microsoft access so I don't really know how to solve this. I would like to use an update query to add a value from a form to a value on a table.
I originally used the SUM expression which gave me an error saying it was an aggregate function.
I also tried to add the two values together (e.g [field1] + [field2]) which as a result gave me a value with both numbers together instead of adding them together.
The following is the SQL I'm using:
UPDATE Votes
SET Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE (((Votes.ActID) = [Forms]![frmVote]![combacts])
AND ((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
I want to add a value [txtnumvotes] a form to a field [NumVotes] from the table [Votes].
Could someone please help me?
You can specify the expected data type with parameters:
PARAMETERS
[Forms]![frmVote]![txtnumvotes] Short,
[Forms]![frmVote]![combacts] Long,
[Forms]![frmVote]![combrndnum] Long;
UPDATE
Votes
SET
Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE
(((Votes.ActID) = [Forms]![frmVote]![combacts])
AND
((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
Without the specification, Access has to guess, and that sometimes fails.
I'm having trouble with this Oracle Merge query.
merge into NEW_DOCTORS NP
USING OLD_DOCTORS MD
on (MD.SSN=NP.SSN OR MD.NPI=NP.NPI OR MD.PIN=NP.PIN)
WHEN MATCHED THEN
UPDATE SET
NP.othervalues=MD.othervalues
NP.PIN/SSN/NPI=MD.PIN/SSN/NPI (**update two of these three that did not return TRUE in the above ON condition)
WHEN NOT MATCHED THEN
insert(NP.SSN,NP.NPI,NP.PIN,NP.other_values)
values(MD.SSN,MD.NPI,MD.PIN,MD.other_values)
Is this possible? Thanks!
EDIT: I'm asking because I read somewhere that fields that are in the ON condition can't be updated. However I'm not sure if the author was talking only in context of the field that evaluates true or for all fields. I'm hoping there's someone who might have an idea about this, as well as any workarounds.
You can use CASE WHEN ... :
UPDATE SET
NP.othervalues=MD.othervalues
,NP.PIN = CASE WHEN (MD.SSN=NP.SSN OR MD.NPI=NP.NPI) THEN MD.PIN ELSE NP.PIN END
,--add here the 2 others
This means, when you have MD.SSN=NP.SSN OR MD.NPI=NP.NPI true, then update NP.PIN with MD.PIN else let the same value NP.PIN
Or you can do 3 differents MERGE, so it will be more readable.
EDIT
Thinking about it, if you update only when this is not the same value (cause it will join only on same value) you can directly update them with the MD table value.
Do that :
NP.othervalues=MD.othervalues
,NP.PIN=MD.PIN
,NP.SSN=MD.SSN
,NP.NPI=MD.NPI
If they match, the update will keep same value, if not it will update the value.