Results 1 to 4 of 4
  1. #1
    drunkenneo is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    199

    Update in Simple Join Query

    I am strucked to a simple join query please help

    Click image for larger version. 

Name:	update.jpg 
Views:	17 
Size:	31.4 KB 
ID:	14446



    Here I want to update the Flag of tblDataentry if any one of the orig or dest is -1 else 0. Please Help
    Last edited by drunkenneo; 11-21-2013 at 04:03 AM. Reason: Added Image

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Are you saying that you want to update the "Flag" field in the tblDataEntry table if either the origin or dest fields in the same table is True (-1)?
    If that is the case, then the Flag field sounds like it is actually a calculated field and should not be stored on the table level, but rather calculated on-the-fly on the query level.

  3. #3
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    This is how I interpret your request. You want to update the tblDataentry.Flag = True if the tblDataentry.origin code found in tblCodes.Cod_Id have True on either tblCodes.airCodes or tblCodes.Flag are True (same with tblDataentry.dest)

    tblDataentry.Flag, tblCodes.airCodes, and tblCodes.Flag are Yes/No data type.

    If that is true, this is how I would do it.
    [SQL]
    UPDATE tblDataentry SET tblDataentry.Flag = True
    WHERE (((Nz(DLookUp("1","tblCodes","Cod_Id = '" & [tblDataentry].[Origin] & "' AND (airCodes = True OR Flag = True)"),0)+Nz(DLookUp("1","tblCodes","Cod_Id = '" & [tblDataentry].[dest] & "' AND (airCodes = True OR Flag = True)"),0))>0));

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I am not saying it cannot be done, but it is not adviced. Doing so usually violates the rules of normalization and is considered a bad programming practice, as it can undermine the integrity of your data and database.
    For example, what happens if at some point down the road, those Origin or Dest fields get changed? The Flag field will NOT update automatically, so your data will not be in agreement.

    The General Rule of Thumb is this: anything that can be calculated off of other fields should NOT be stored in a table. It should be calculated in a query, where it is dynamic.

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

Similar Threads

  1. Replies: 6
    Last Post: 09-11-2013, 11:32 PM
  2. Replies: 1
    Last Post: 05-08-2013, 07:08 PM
  3. Replies: 3
    Last Post: 11-10-2012, 07:52 AM
  4. Simple Update Query
    By guygodwin in forum Queries
    Replies: 1
    Last Post: 02-16-2012, 10:59 PM
  5. Replies: 3
    Last Post: 12-20-2010, 09:22 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