Results 1 to 5 of 5
  1. #1
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73

    Unhappy IIf function

    How do I do to use the IIf function and calculate the totals in rows and columns in this query?

    SELECT [tbl_EAH_Sig].SigID, [bl_EAH_Sig].AmaID, [tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value] AS Expr1


    FROM tbl_Hat INNER JOIN tbl_EAH_Sig ON [tbl_Hat].AmaID = [tbl_EAH_Sig].AmaID
    GROUP BY [tbl_EAH_Sig].SigID, [tbl_EAH_Sig].AmaID, [tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value];

    Many thanks

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    what do you want to do with IIF?

    you didn't tell us what do you want, so I just guess you want a sum of [tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value], in this case, the query should be:

    SELECT [tbl_EAH_Sig].SigID, [bl_EAH_Sig].AmaID, sum([tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value]) AS Expr1
    FROM tbl_Hat INNER JOIN tbl_EAH_Sig ON [tbl_Hat].AmaID = [tbl_EAH_Sig].AmaID
    GROUP BY [tbl_EAH_Sig].SigID, [tbl_EAH_Sig].AmaID

  3. #3
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73

    Unhappy IIf

    Quote Originally Posted by weekend00 View Post
    what do you want to do with IIF?

    you didn't tell us what do you want, so I just guess you want a sum of [tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value], in this case, the query should be:

    SELECT [tbl_EAH_Sig].SigID, [bl_EAH_Sig].AmaID, sum([tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value]) AS Expr1
    FROM tbl_Hat INNER JOIN tbl_EAH_Sig ON [tbl_Hat].AmaID = [tbl_EAH_Sig].AmaID
    GROUP BY [tbl_EAH_Sig].SigID, [tbl_EAH_Sig].AmaID
    Many thanks
    I'm new to sql. I'm sorry I wrote a mistake in my SQL code

    Yes I need the IFF with Sum. My idea is to have a row title as a column title
    II already fixed my mistake like this
    SELECT tbl_EAH_Sig.SigID, [tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value] AS Expr1
    FROM tbl_Hat INNER JOIN tbl_EAH_Sig ON tbl_Hat.AnimalID = tbl_EAH_Sig.AmalID
    GROUP BY tbl_EAH_Sig.SigID, [tbl_EAH_Sig]![Anils]*[tbl_Hat]![Value];




    I think I have to write something in the SQL code like



    Sum((IIf([AmalID]="02",[Anils],0))) AS Expr1
    Sum((IIf[Hat]="01",[Value],0)))


    But I have been breaking my head with no success.
    Could you give an idea how to do it?

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if you meant you want the sum of Anils * Value for those having [aMalID]='02' and [hat]='01'? you don't need IIF, just use where clause:

    SELECT tbl_EAH_Sig.SigID, Sum([Anils] * [Value]) AS Expr1
    FROM tbl_Hat INNER JOIN tbl_EAH_Sig ON tbl_Hat.AnimalID = tbl_EAH_Sig.AmalID
    where [aMalID]='02' and [hat]='01'
    GROUP BY tbl_EAH_Sig.SigID

  5. #5
    seb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    73

    Unhappy Iff

    Quote Originally Posted by weekend00 View Post
    if you meant you want the sum of Anils * Value for those having [aMalID]='02' and [hat]='01'? you don't need IIF, just use where clause:

    SELECT tbl_EAH_Sig.SigID, Sum([Anils] * [Value]) AS Expr1
    FROM tbl_Hat INNER JOIN tbl_EAH_Sig ON tbl_Hat.AnimalID = tbl_EAH_Sig.AmalID
    where [aMalID]='02' and [hat]='01'
    GROUP BY tbl_EAH_Sig.SigID
    Many thanks
    With your idea I found what I need as first step with the following code:
    SELECT tbl_EAH_Sig.SigID, Sum(IIf([AmalID]="01",[Anils],0))*1 AS VaPa, Sum(IIf([AmalID]="02",[Anils],0))*1 AS VaSe, Sum(IIf([AmalID]="07",[Anils],0))*0.25 AS Teras, Sum(IIf([AmalID]="08",[Anils],0))*0.25 AS Teros, [VaPa]+[VaSe]+[Teras]+[Teros]+ AS [Total UA]
    FROM tbl_Hat INNER JOIN tbl_EAH_Sig ON tbl_Hat.AmalID = tbl_EAH_Sig.AmalID
    GROUP BY tbl_EAH_Sig.SigID;

    As in my previous message I would like to calculate in nthis query or in another the totals for each column (VaPa, VaSe, Teras, Teros). Could you suggest how to do it?
    Thanks againg

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with AVG function
    By techexpressinc in forum Reports
    Replies: 1
    Last Post: 03-23-2010, 07:47 AM
  2. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  3. Sum Function Help
    By newbie in forum Reports
    Replies: 3
    Last Post: 06-30-2009, 05:32 PM
  4. function key
    By marianne in forum Access
    Replies: 5
    Last Post: 05-14-2009, 01:26 AM
  5. Avg Function
    By hiker8117 in forum Access
    Replies: 3
    Last Post: 04-23-2009, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums