dbTalk Databases Forums  

if/then query

comp.databases.ms-access comp.databases.ms-access


Discuss if/then query in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JBoeker@gmail.com
 
Posts: n/a

Default if/then query - 12-17-2004 , 08:26 PM






Hello,

I have 3 tables in my mdb file, one contains a list of definitions, one
is a list physical items, and one is a list overrides. Normally my
query will join the definition physical item tables, sharing an id
number (e.g. in my defintion file I may have a table item and its
price, item number, etc; in my physical item table I may list sales
date, purchaser etc; the query result will combine these).

Sometimes I would like to override one of the definition columns with a
value in an override table. Is it possible to write an SQL query in
access that does this? I imagine something using the IIf operator.
Thanks,

Jeff


Reply With Quote
  #2  
Old   
HS Hartkamp
 
Posts: n/a

Default Re: if/then query - 12-18-2004 , 04:03 PM







Make a join of all three tables, and extract a column
Result: iif ( [tblOverride] is null;
[tblDefinition].[columnX];[tblOverride].[ColumnXorY])
(type this in the top-row of the bottom half of your query-design-view)

Make sure you have a left-join to the override table (arrow pointing to
override), because you'd miss records otherwise. To make sure, first select
your results, note the recordcount, and than add the override-table to your
query. If the recordcount is the same, it's OK.

Bas Hartkamp



<JBoeker (AT) gmail (DOT) com> wrote

Quote:
Hello,

I have 3 tables in my mdb file, one contains a list of definitions, one
is a list physical items, and one is a list overrides. Normally my
query will join the definition physical item tables, sharing an id
number (e.g. in my defintion file I may have a table item and its
price, item number, etc; in my physical item table I may list sales
date, purchaser etc; the query result will combine these).

Sometimes I would like to override one of the definition columns with a
value in an override table. Is it possible to write an SQL query in
access that does this? I imagine something using the IIf operator.
Thanks,

Jeff




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.