473,411 Members | 2,148 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,411 software developers and data experts.

IIf function for 2 parameters

Hi
I would really appreciate some help. I'm not very good at Access and right now I have to make an Database for part of an Internship project. So this Q might seem silly to you but I really don't know hoz to proceed!

I've got a table with products and their prices, however the prices changed recently and from one exact date to another they should show this on my table.
The product numbers haven't changed however. If there some function like the IIf function which supports 2 parameters?

Thanks in advance!!!
Jul 23 '07 #1
15 5109
ilearneditonline
130 Expert 100+
Hi
I would really appreciate some help. I'm not very good at Access and right now I have to make an Database for part of an Internship project. So this Q might seem silly to you but I really don't know hoz to proceed!

I've got a table with products and their prices, however the prices changed recently and from one exact date to another they should show this on my table.
The product numbers haven't changed however. If there some function like the IIf function which supports 2 parameters?

Thanks in advance!!!
So is this a MySQL question or an Access question since you said you are not good at access.

If it is MySql you can use
Expand|Select|Wrap|Line Numbers
  1. IF(condition, true, false) 
.See mysql documentation.

If it is Access then you use
Expand|Select|Wrap|Line Numbers
  1. IIF(condition, true, false)
. See Access Online.
Jul 24 '07 #2
r035198x
13,262 8TB
So is this a MySQL question or an Access question since you said you are not good at access.

If it is MySql you can use
Expand|Select|Wrap|Line Numbers
  1. IF(condition, true, false) 
.See mysql documentation.

If it is Access then you use
Expand|Select|Wrap|Line Numbers
  1. IIF(condition, true, false)
. See Access Online.
And now this lies in the Access forum
Jul 25 '07 #3
Hi
Yes but I can only unsthe IIF Function for one parameter. The thing is, i need something which says: iif delivery date>31.06.07 and productnumber is 789456-123, then 400$, if delivery date <31.06.07 and productnumber 789456-123 then 450$.

Thanks already for your help!
Jul 26 '07 #4
ilearneditonline
130 Expert 100+
Hi
Yes but I can only unsthe IIF Function for one parameter. The thing is, i need something which says: iif delivery date>31.06.07 and productnumber is 789456-123, then 400$, if delivery date <31.06.07 and productnumber 789456-123 then 450$.

Thanks already for your help!
So why not use

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (deliverydate >) 31.06.07 and (productnumber = 789456-123) then
  3.     retval = 400 
  4. elseif (deliverydate < 31.06.07) and (productnumber = 789456-123) then
  5.     retval = 450
  6. end if
  7.  
Jul 26 '07 #5
JKing
1,206 Expert 1GB
Hi
Yes but I can only unsthe IIF Function for one parameter. The thing is, i need something which says: iif delivery date>31.06.07 and productnumber is 789456-123, then 400$, if delivery date <31.06.07 and productnumber 789456-123 then 450$.

Thanks already for your help!
You could use nested iifs.

Expand|Select|Wrap|Line Numbers
  1. iif([Delivery Date] > #31/06/07#, iif([ProductNumber] = 789456-123, 400$, 0$),iif([ProductNumber] = 789456-123, 450$, 0$))
  2.  
Jul 26 '07 #6
You could use nested iifs.

Expand|Select|Wrap|Line Numbers
  1. iif([Delivery Date] > #31/06/07#, iif([ProductNumber] = 789456-123, 400$, 0$),iif([ProductNumber] = 789456-123, 450$, 0$))
  2.  
Hi
The thing is, all my products have new prices. is there a possiblity of saying iif (d.d > 31.06.07, "new_price", "old price") if i have the old and new prices in a related table?

Thanks!
Jul 30 '07 #7
Killer42
8,435 Expert 8TB
The thing is, all my products have new prices. is there a possiblity of saying iif (d.d > 31.06.07, "new_price", "old price") if i have the old and new prices in a related table?
Well, I suppose the performance might be abysmal, but you could create a function in VBA which looks up the appropriate price, then just call that function in your query.
So instead of building an elaborate IIF() setup, you'd just use something like PriceAsAtDate(DateField, ProductField).

Depending on the size and volatility of the data, it might be worth caching in an array or something, to speed up these lookups.
Jul 30 '07 #8
JKing
1,206 Expert 1GB
Yes, you can have it return the values of another table. You'd simply have to switch the values with the field names of the new and old prices. If your tables are properly related everything should match up just fine.
Jul 30 '07 #9
Yes, you can have it return the values of another table. You'd simply have to switch the values with the field names of the new and old prices. If your tables are properly related everything should match up just fine.
Yes but the thing is I still need the old prices. I have to give out warranty claims and for older orders the warranty claim should match up with the old price.
Jul 31 '07 #10
Killer42
8,435 Expert 8TB
Yes but the thing is I still need the old prices. I have to give out warranty claims and for older orders the warranty claim should match up with the old price.
It seems as though it should be possible to use some sort of aggregate function or something, to retrieve the first record which matches one field and is equal to or less than another field.

Bear with me, I'm just thinking out loud, here...

If your lookup table had a field which had the product ID (forget what it's called) and the date combined, then all you'd need do is find the first record in sequence, starting from Product&Date, sorted descending.

I'm going to see whether I can get some real Access gurus to pop in, as I'm getting out of my depth.
Jul 31 '07 #11
NeoPa
32,556 Expert Mod 16PB
Killer's on the right lines here.
You need to separate out the products from the prices. Prices need to be dated so something like :
Table Name=tblProduct
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. ProdID; Autonumber; PK
  3. ProdDesc; String
  4. ... Other product specific info
Table Name=tblProdPrice
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. ProdPriceID; Autonumber; PK
  3. ProdID; number; CFK (part of compound key)
  4. PriceDate; Date/Time; CFK
  5. Price; Numeric
Link in the two tables on [ProdID] and select only the dates you want in your WHERE clause.
Jul 31 '07 #12
Killer42
8,435 Expert 8TB
And presumably you can use a <= operator in the WHERE clause. Requiring an exact match wouldn't be much help.

But, how would you ensure that you got the latest as at that date? In other words, let's say the price has changed five times. For a given date, you would need the last price set on or before that date, but not the earlier ones. How would you specify, in SQL, that you want the first (or last) value in the key range? This is what stumped me.
Jul 31 '07 #13
NeoPa
32,556 Expert Mod 16PB
Use the WHERE clause to exclude any after the date you want then use the Max() aggregate function to select the most appropriate record from those that are left.
Jul 31 '07 #14
Killer42
8,435 Expert 8TB
Use the WHERE clause to exclude any after the date you want then use the Max() aggregate function to select the most appropriate record from those that are left.
Ahah! Max() is what I was thinking of. I knew there was something that would do it. Thanks, NeoPa.
Aug 1 '07 #15
NeoPa
32,556 Expert Mod 16PB
No probs Killer :)
I should have mentioned (for Joe Public) that the GROUP BY clause is also required, but I'm sure you don't need telling that.
Aug 1 '07 #16

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

Similar topics

1
by: David Isaac | last post by:
Alan Isaac wrote: > Default parameter values are > evaluated once when the function definition is > executed. Where are they stored? ... Where is this documented? Forgive any poor phrasing: I'm...
1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
11
by: BRG | last post by:
I know that default template arguments cannot be used in function templates but are default function parameters legal? That is, is this: ---------------------------------- #include <functional>...
27
by: Marlene Stebbins | last post by:
I am experimenting with function pointers. Unfortunately, my C book has nothing on function pointers as function parameters. I want to pass a pointer to ff() to f() with the result that f() prints...
1
by: Martin Dařílek | last post by:
Hi all, please can You help me with translation of function parameters provided by p2smon.dll library (Crystal Reports)? Any example, which I found, is only in VB (I don't like it :-) I would...
3
by: Iker Arizmendi | last post by:
How are function parameters of rowtype specified when calling them from a client such as libpq? Is there a syntax similar to that for arrays? (eg, {x, y, z} ) Thanks, Iker ...
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
2
by: Jason | last post by:
Hello: First, if this is one of those "questions asked a million times" just say so and I'll dig a little deeper. If not, then... I'm curious, is it typical to use member data (properties,...
7
by: lovecreatesbea... | last post by:
Shoud we declare non-pointer function parameters with const keywords? int main(void){ int f(const int i); int i; f(i); return 0; }
3
by: =?ISO-8859-15?Q?Jean=2DFran=E7ois?= Lemaire | last post by:
Hello, I'm having a discussion with someone who sustains that function parameters, when they are smaller than an int (say short or char) are automatically promoted to int before being passed to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.