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
8 6179 @buddyr - SELECT Table1.Number, Table1.Date, Table1.Warranty,
-
IIf([Number]=30 And [Date]>#1/10/2006#,"Off","On") AS [Warranty Status]
-
FROM Table1;
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
NeoPa 32,556
Expert Mod 16PB
To update all the values in your table, you could use the following SQL : - UPDATE [Table1]
-
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.
@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. - SELECT Table1.ID, Table1.Number, Table1.Date, Table1.Warranty,
-
fCalcWarrantyStatus([Number],[Date]) AS Warranty_Status
-
FROM Table1;
- Public Function fCalcWarrantyStatus(lngNumber As Long, dteDate As Date) As Variant
-
If dteDate > #1/10/2006# Then
-
Select Case lngNumber
-
Case 10
-
fCalcWarrantyStatus = "On/Off"
-
Case 20
-
fCalcWarrantyStatus = "On/Off"
-
Case 30
-
fCalcWarrantyStatus = "Off" 'Known Response
-
Case 40
-
fCalcWarrantyStatus = "On/Off"
-
Case 50
-
fCalcWarrantyStatus = "On/Off"
-
Case 60
-
fCalcWarrantyStatus = "On/Off"
-
Case 70
-
fCalcWarrantyStatus = "On/Off"
-
Case 80
-
fCalcWarrantyStatus = "On/Off"
-
Case 90
-
fCalcWarrantyStatus = "On/Off"
-
Case 100
-
fCalcWarrantyStatus = "On/Off"
-
Case ...
-
fCalcWarrantyStatus = "On/Off"
-
Case Else
-
fCalcWarrantyStatus = "On/Off"
-
End Select
-
Else
-
fCalcWarrantyStatus = Null 'Date <= 1/10/2006
-
End If
-
End Function
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.
NeoPa 32,556
Expert Mod 16PB
No worries BuddyR. Did you read through all the earlier posts?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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...
| |