Results 1 to 5 of 5
  1. #1
    compooper is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    87

    Sql iif statement, column?

    Hi folks,

    I'm trying to write a query with an IIF statement that displays service names.

    SELECT IIf([TestTable].[Svc_SubAcct]=9,[Testtable].[Svc_ComName],[Testtable].[Svc_SubAcct]) AS Service, Count(IIf([TestTable].[Svc_SubAcct]=9,[Testtable].[Svc_ComName],[Testtable].[Svc_SubAcct])) AS [Count], TestTable.CompanyID, TestTable.InvTypeID, TestTable.InvPeriod
    FROM TestTable
    GROUP BY IIf([TestTable].[Svc_SubAcct]=9,[Testtable].[Svc_ComName],[Testtable].[Svc_SubAcct]), TestTable.CompanyID, TestTable.InvTypeID, TestTable.InvPeriod;

    Problem:
    Testtable.Svc_SubAcct is a combobox/lookup field
    [Testtable].[Svc_ComName] is a combobox/lookup field
    The query is displaying the number column vs. the text column that I want it to display
    I know in vba I can refer to the column using .column(#)
    But that doesn't seem to work in SQL.


    ANy ideas?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Please explain the combobox/lookup field.

    Lookups (combo and listboxes) on forms are not an issue and are very common. However, lookup fields at the table level are the problem; this site
    http://access.mvps.org/access/lookupfields.htm
    explains why.

  3. #3
    compooper is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    87
    Testtable.Svc_SubAcct is a Number field with a lookup field:
    SELECT [GLSUBID], [GLsubheading] FROM [GLaccounts-sub] ORDER BY [GLsubheading];

    [Testtable].[Svc_ComName] is similiar

    Is there anyway to select a column in VBA when creating a pivottable?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    I don't understand this statement

    Testtable.Svc_SubAcct is a Number field with a lookup field: Tell me about the lookup field.

  5. #5
    compooper is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    87
    Okay let me clarify:

    Testtable.Svc_SubAcct
    Data Type: Number
    Row Source: SELECT [GLSUBID], [GLsubheading] FROM [GLaccounts-sub] ORDER BY [GLsubheading];

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

Similar Threads

  1. sales DB selecting column and column range
    By pher77 in forum Queries
    Replies: 3
    Last Post: 06-11-2011, 04:04 PM
  2. Replies: 1
    Last Post: 03-14-2011, 10:04 AM
  3. Replies: 7
    Last Post: 04-27-2010, 02:47 PM
  4. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  5. inserting values in column based another column
    By wasim_sono in forum Database Design
    Replies: 1
    Last Post: 06-27-2006, 05:23 AM

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