473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

iif statement to change value in field

107 100+
Hello,
if I have a table1
(3 fields) number date warranty
10 1/15/09 on
20 4/10/05 off
30 5/11/04 on
40 8/21/08 on

can I write a conditional iif statement that says if number = 30 and date > 1/10/06 then warranty = off?

Where would I write it - in the sql statement in a query?
The database already has about 5000 records in it and can an if statement change a field that already has data in it. Or should I be doing it in vb?
any ideas
thank you
Jun 4 '09 #1
8 6179
ADezii
8,834 Expert 8TB
@buddyr
Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.Number, Table1.Date, Table1.Warranty,
  2. IIf([Number]=30 And [Date]>#1/10/2006#,"Off","On") AS [Warranty Status]
  3. FROM Table1;
Jun 4 '09 #2
buddyr
107 100+
thank you that works
if I want to make statement use more than one number- can I use a select case statement in access
thank you
Jun 4 '09 #3
NeoPa
32,556 Expert Mod 16PB
To update all the values in your table, you could use the following SQL :
Expand|Select|Wrap|Line Numbers
  1. UPDATE [Table1]
  2. SET [Warranty]=IIf([Number]=30 And [Date]>#1/10/2006#,'Off','On')
NB however, updates are often used to change stored vales when those values are simply calculations. This is rarely a good idea. Instead you should calculate the values as and when required. For further explanation see Normalisation and Table structures.
Jun 4 '09 #4
NeoPa
32,556 Expert Mod 16PB
@buddyr
What do you mean?
Jun 4 '09 #5
ADezii
8,834 Expert 8TB
@buddyr
Buddr, the logic would have to change dramatically. Assuming the Date Value of 1/10/2006 is Constant and only the Number is Variable, then the Calculated Field [Warranty_Status] would have to Call a Public Function and pass to it 2 Arguments to be analyzed, then the appropriate result returned.
Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.ID, Table1.Number, Table1.Date, Table1.Warranty,
  2. fCalcWarrantyStatus([Number],[Date]) AS Warranty_Status
  3. FROM Table1;
Expand|Select|Wrap|Line Numbers
  1. Public Function fCalcWarrantyStatus(lngNumber As Long, dteDate As Date) As Variant
  2. If dteDate > #1/10/2006# Then
  3.   Select Case lngNumber
  4.     Case 10
  5.       fCalcWarrantyStatus = "On/Off"
  6.     Case 20
  7.       fCalcWarrantyStatus = "On/Off"
  8.     Case 30
  9.       fCalcWarrantyStatus = "Off"       'Known Response
  10.     Case 40
  11.       fCalcWarrantyStatus = "On/Off"
  12.     Case 50
  13.       fCalcWarrantyStatus = "On/Off"
  14.     Case 60
  15.       fCalcWarrantyStatus = "On/Off"
  16.     Case 70
  17.       fCalcWarrantyStatus = "On/Off"
  18.     Case 80
  19.       fCalcWarrantyStatus = "On/Off"
  20.     Case 90
  21.       fCalcWarrantyStatus = "On/Off"
  22.     Case 100
  23.       fCalcWarrantyStatus = "On/Off"
  24.     Case ...
  25.       fCalcWarrantyStatus = "On/Off"
  26.     Case Else
  27.       fCalcWarrantyStatus = "On/Off"
  28.   End Select
  29. Else
  30.   fCalcWarrantyStatus = Null    'Date <= 1/10/2006
  31. End If
  32. End Function
Jun 4 '09 #6
NeoPa
32,556 Expert Mod 16PB
There is no CASE statement in Access (Jet) SQL (unlike in T-SQL for instance), although ADezii has illustrated that there is in VBA.

Access handles this using (possibly multiple) IIF() function calls.
Jun 4 '09 #7
buddyr
107 100+
thanks for explaining it
Jun 5 '09 #8
NeoPa
32,556 Expert Mod 16PB
No worries BuddyR. Did you read through all the earlier posts?
Jun 5 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
7
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
4
by: kathy | last post by:
Working in a form, I have an Iif statement where if a date is not filled in, another field will show as a blank. If the date IS filled in, the 2nd field will show its actual value. The following...
2
by: Kevin | last post by:
Hi I have Created A form to allow the user to query a text field which is a name i am trying to create a query that runs of a button. this works fine if the user wnters the entire contents...
8
by: Brian Basquille | last post by:
Hello all, Bit of a change of pace now. As opposed to the typical questions regarding my Air Hockey game, am also working on a Photo Album which uses an Access Database to store information...
24
by: Mark | last post by:
Hi - how can I get a switch statement to look for a range of values? I have: function payCalc(field, field2) switch(field.value) { case 0-50: field2.value="lower band"; case 51-99:...
6
by: asadikhan | last post by:
Hello, I have a bit of a design issue around this application I am developing, and I just want to run it through some of the brains out here. So I have a table called ErrorCheck which...
8
by: Lebbsy | last post by:
I have two combobox fields with the second combobox (Department) dependent on the first combobox (Ministry). If the value of the first combobox changes the options in the second combobox should...
40
by: chhines | last post by:
I have a very long IIf statement. I think maybe I've reached the limit of how many choices you can have in the control source "Build" statement of a text box on a form. Really, the IIF statement is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.