Re: Why does this Nested IIF statement add AS fields



Hi Jacqelyn,

when you create a calculated field in the query design screen, Access assigns an 'alias' (what to call it) to the new fieldname. you can change Expr1, Expr2, etc to suit your desires. It is a good idea, however, to make the calculated fieldname different than any fieldname in the source tables so Access does not get confused.

If I have a calculated field based on Fieldname and want it to look the same but be different, I just add an underscore to the end --> Fieldname_

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.accessmvp.com/Strive4Peace/Index.htm

*
(: have an awesome day :)
*



jacqelynl wrote:
Could someone please explain why this happens and a possible solution to the
problem? I am using ACCESS 2003 and the query type is "make table".

This query works within a Select statement. If I use the below code, all is
well.

...IIf([period_status2]="C" And [Month]=2,[current_balance2],IIf(
[Current_balance2]=0,[current_balance2]+[current_balance1],opening_balance))
AS [P3Overall Balance] INTO Phase3Data....

Unfortunately, I need to add the additional code shown below to the query so
that the entire year is coded and I can distribute this database. When I use
the code below, the query saves as shown below, adding an AS statement after
each nested IIF statement.

IIf([Current_balance2]=0,[current_balance2]+[current_balance1], IIf(
[period_status2]="C" And [Month]=2,[current_balance2])) AS Expr1, IIf([Current_balance3]=0,[current_balance3]+[current_balance2], IIf(
[period_status3]="C" And [Month]=3,[current_balance3])) AS Expr2, IIf([Current_balance4]=0,[current_balance4]+[current_balance3], IIf(
[period_status4]="C" And [Month]=4,[current_balance4])) AS Expr3, IIf([Current_balance5]=0,[current_balance5]+[current_balance4], IIf(
[period_status5]="C" And [Month]=5,[current_balance5])) AS Expr4, IIf([Current_balance6]=0,[current_balance6]+[current_balance5], IIf(
[period_status6]="C" And [Month]=6,[current_balance6])) AS Expr5, IIf([Current_balance7]=0,[current_balance7]+[current_balance6], IIf(
[period_status7]="C" And [Month]=7,[current_balance7])) AS Expr6, IIf([Current_balance8]=0,[current_balance8]+[current_balance7], IIf(
[period_status8]="C" And [Month]=8,[current_balance8])) AS Expr7, IIf([Current_balance9]=0,[current_balance9]+[current_balance8], IIf(
[period_status9]="C" And [Month]=9,[current_balance9])) AS Expr8, OPENING_BALANCE AS [P3Overall Balance] INTO Phase3Data

What it is supposed to do is follow the IIFs and add the new field [P3Overall
Balance] populated with the data.

Thank you!

.



Relevant Pages

  • Re: Importing Text File that is vertically oriented
    ... the Value corresponding to any FieldName. ... Create a query on the table that returns both fields and a dummy ... >I would ideally like to setup a linked table to import this data - does ... John Nurick [Microsoft Access MVP] ...
    (microsoft.public.access.externaldata)
  • Re: how do I mix same fields from two table in field by query
    ... and you want to get a result made of the fields fieldName from ... SELECT fieldName FROM table1 ... query in the query designer. ... All caps words are keyword to be typed as I ...
    (microsoft.public.access.queries)
  • Re: The like clause of sql
    ... Are you using a form to enter a value and you want to build a query string ... > Its not that simple because Tablename.FieldName is a fieldname ... > but then i get Syntax error in query expression '(%email% LIKE ... >> SELECT Tablename.* ...
    (microsoft.public.access.queries)
  • Re: Help With The Code
    ... I did leave your query in there (I had copied it into the message to ... Fieldname ... The first table would be a modified GRS Record table, ... You can then create a "Normalizing Union Query" to migrate data from your ...
    (microsoft.public.access.forms)
  • Re: Else If Statements
    ... are saying I would have first take the select query with the calculated field ... in it and make it into a make table query and then do another select query. ... Within the origional table there is a post code field. ... postcode down to only show the first part of the postcode i.e. the alpha ...
    (microsoft.public.access.queries)