Results 1 to 3 of 3
  1. #1
    RandV is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2013
    Posts
    12

    When changing name of SELECT column with "as [New Name]", how to use New Name in WHERE clause?

    This is something that seems simple but I've never quite been able to figure out, I've usually worked around it, but now have a situation where I don't think I can. To put it simply, if in my select clause I have:

    Code:
    SELECT TABLE.COL1 as [New Field]
    How do I use [New Field] in the WHERE clause?

    Code:
    WHERE [New Field] > 1;
    When I do it look that it prompts me for the parameter for "New field".

    To elaborate a little further, what I have at the moment is I'm splitting up a string field to a date field, format YYYYMMDD to M/D/YYYY, then I want to filter that by a date range.



    Code:
    SELECT CDATE( 
    MID(SALES_HISTORY_HEADER.IN_DATE, 5, 2) + "/" +
    RIGHT(SALES_HISTORY_HEADER.IN_DATE, 2) + "/" +
    LEFT(SALES_HISTORY_HEADER.IN_DATE, 4)
    ) AS [Invoice Date]
    WHERE [Invoice Date] between #[Start Date]# and #[End Date]#
    But I can't get the query to pick up on [Invoice Date], regardless of how I name it. Any help would be appreciated, thanks.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I don't think Access is aware of Invoice Date at the time. Usually you have to repeat the calculation/expression where you first defined it.

    you could try (untested)

    Code:
    SELECT [INVOICE DATE] FROM
    (
    SELECT CDATE( 
    MID(SALES_HISTORY_HEADER.IN_DATE, 5, 2) + "/" +
    RIGHT(SALES_HISTORY_HEADER.IN_DATE, 2) + "/" +
    LEFT(SALES_HISTORY_HEADER.IN_DATE, 4)
    ) AS [Invoice Date]
    )
    WHERE [Invoice Date] between #[Start Date]# and #[End Date]#

    But why are you NOT storing IN_Date as a Date Datatype?

  3. #3
    RandV is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Mar 2013
    Posts
    12
    Quote Originally Posted by orange View Post
    I don't think Access is aware of Invoice Date at the time. Usually you have to repeat the calculation/expression where you first defined it.

    you could try (untested)

    Code:
    SELECT [INVOICE DATE] FROM
    (
    SELECT CDATE( 
    MID(SALES_HISTORY_HEADER.IN_DATE, 5, 2) + "/" +
    RIGHT(SALES_HISTORY_HEADER.IN_DATE, 2) + "/" +
    LEFT(SALES_HISTORY_HEADER.IN_DATE, 4)
    ) AS [Invoice Date]
    )
    WHERE [Invoice Date] between #[Start Date]# and #[End Date]#

    But why are you NOT storing IN_Date as a Date Datatype?
    Got it, thanks. And not my call with the Date type here, I'm working between two different databases to pull some common data together with a UNION query. One uses proper dates, the other the string.

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

Similar Threads

  1. Column sum works in "Detail" but not "Footer"
    By Doodlebug2000 in forum Reports
    Replies: 1
    Last Post: 12-10-2012, 03:20 PM
  2. "AND" or "&" in the FROM clause of a query
    By kelann in forum Queries
    Replies: 21
    Last Post: 11-09-2012, 08:41 AM
  3. Replies: 1
    Last Post: 10-08-2012, 09:01 AM
  4. Custum Functions in Query "WHERE" Clause
    By trb5016 in forum Queries
    Replies: 1
    Last Post: 02-15-2012, 03:30 PM
  5. ComboBox "Select" and "DLookUp"
    By witooldas in forum Forms
    Replies: 0
    Last Post: 03-23-2011, 03:31 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