+ Reply to Thread
Results 1 to 3 of 3

Use of calculated field in "WHERE" part of SQL statement?

  1. #1
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    42

    Use of calculated field in "WHERE" part of SQL statement?

    Dear Microsoft Gurus,
    I am teaching myself Microsoft Access 2007. So, please forgive me if this question is very naive.

    I tried the following two queries that I expected to give the same answer (pull out the rows with both [Amount Paid] and [Current Due] set to zero). The first of these two queries worked as expected. The second query Asks me for [Total Amount] instead of calculating it.

    Does this mean that calculated fields cannot be used in an SQL query in the "Where" part of the SQL statement, or am I simply doing it wrong in Query 2?

    Query 1 (works as expected):
    SELECT [Client Number], [Client Name], [Amount Paid], [Current Due], [Amount Paid] + [Current Due] AS [Total Amount]
    FROM Client_table
    Where ([Amount Paid] =0) AND ( [Current Due] = 0 )
    ;

    Query 2 ( Asks me for [Total Amount] instead of calculating it)

    SELECT [Client Number], [Client Name], [Amount Paid], [Current Due], [Amount Paid] + [Current Due] AS [Total Amount]
    FROM Client_table
    Where [Total Amount]= 0
    ;

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,706

    Re: Use of calculated field in "WHERE" part of SQL statement?

    Change your SQL statement to read:

    Please Login or Register  to view this content.
    You have to spell out the expression as Access does not understand the alias as a field name unless it is used in a subsequent query with this one as the record source.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    02-07-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    42

    Re: Use of calculated field in "WHERE" part of SQL statement?

    Hi Alan,
    That's great! Thank you very much. I truly appreciate your quick, clear repliues that not only answer my query, but also teach me "the next step".

    Studiosa.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2013, 12:45 PM
  2. Replies: 9
    Last Post: 09-05-2012, 10:23 AM
  3. Replies: 3
    Last Post: 12-14-2006, 01:36 PM
  4. [SOLVED] where can I find the "Calculated Field" in Office 2007 version?
    By bruno in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-14-2006, 04:00 PM
  5. Replies: 3
    Last Post: 05-27-2005, 06:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1