Results 1 to 4 of 4
  1. #1
    Shiva kumar is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Location
    Bangalore
    Posts
    3

    Create subquery for my 2 queries as am unable to do so..

    Hello,
    Am new to the Access and trying to merge below the 2 queries into one. but am not able to the same. Given the details below... Please create a subquery for the below and do the needful.

    1st Query:
    SELECT distinct A.[Order Number], A.[Sales document], A.[Prodno _salesdoc Combi], IIf(IsNull([B].[Created Date]),"Yes",[B].[Created Date]) AS Expr1
    FROM Serialized_Report_final_AND_Mapping_filds AS A LEFT JOIN BEX_Report AS B ON A.[Prodno _salesdoc Combi] = B.[Pdt+SO# Combination];

    2nd Query:
    SELECT DISTINCT Y.[Order Number],Y.[Sales document],Y.[Prodno _salesdoc Combin], IIf(Y.[Created Dates]="Yes",IIf(IsNull(Z.[Created Date]),"Sales Order not found","Sales order found with product mismatch"),Y.[Created Dates]) AS Expr5
    FROM 30_days_BEXReport AS Y LEFT JOIN BEX_Report AS Z ON Y.[Sales document] = Z.[Sales document];



    And [Order Number] is the unique field.

    I inserted 2nd Query in the 1st query where its required as below;

    SELECT distinct A.[Order Serial1 Number], A.[Sales document], A.[Prodno _salesdoc Combi], IIf(IsNull([B].[Created Date]),(SELECT DISTINCT Y.[Order Serial1 Number],Y.[Sales document],Y.[Prodno _salesdoc Combin], IIf(Y.[Created Dates]="Yes",IIf(IsNull(Z.[Created Date]),"Sales Order not found","Sales order found with product mismatch"),Y.[Created Dates]) AS Expr5
    FROM 30_days_BEXReport AS Y LEFT JOIN BEX_Report AS Z ON Y.[Sales document] = Z.[Sales document]),[B].[Created Date]) AS Expr1
    FROM Serialized_Report_final_AND_Mapping_filds AS A LEFT JOIN BEX_Report AS B ON A.[Prodno _salesdoc Combi] = B.[Pdt+SO# Combination];

    By running the above subquery, i have got this error

    " You have written a subquery that can return more than one field without using the EXISTS reserverd word in the main query's FROM caluse. Revise the SELECT Statement of the subquery to request one new field."

  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,870
    I recommend that you tell readers (and yourself) exactly WHAT you are trying to accomplish. You have told us only HOW you want to do something, and there may be options, but we need to know What you are trying to achieve.

    As an aside, you should adopt a naming convention that does NOT allow embedded spaces in field and object names. It will save you from many frustrating syntax errors

  3. #3
    Shiva kumar is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Location
    Bangalore
    Posts
    3
    Thanks for your interest to reply....
    i will try to put it in simple terms; say, in excel i have 2 sheets - 1st sheet has [product no] and [SAP document no] columns and 2nd sheet also has same columns plus additional [created date] column.
    My requirement is, in 1st sheet, in the new column i need to get created date from 2nd sheet for which the [product no] is same in both sheets.
    After this for which [product no] is not found in the 2nd sheet i need to give second condition that is check for the [SAP document no] in 2nd sheet, if [SAP document no] is found i want to have " [SAP document no] is available but [product no] is not available" . if it is not found it should give "[SAP document no] is not available" in the new column in 1st sheet.

    not exactly but it may look as below in excel formula; the same i am implementing in Access.
    =IF(ISERROR(VLOOKUP(H7,Sale_Report!$A:$L,1,0)=TRUE ),IF(ISERROR(VLOOKUP(C7),Sale_Report!$O:$O,1,0)=TR UE),"[SAP document no] is not available","[SAP document no] is available but [product no] is not available"),VLOOKUP(H7,Sale_Report!$A:$L,12,0))

    I hope it may give some clarifications....

  4. #4
    Shiva kumar is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2014
    Location
    Bangalore
    Posts
    3
    Quote Originally Posted by orange View Post
    I recommend that you tell readers (and yourself) exactly WHAT you are trying to accomplish. You have told us only HOW you want to do something, and there may be options, but we need to know What you are trying to achieve.

    As an aside, you should adopt a naming convention that does NOT allow embedded spaces in field and object names. It will save you from many frustrating syntax errors

    Thanks for your interest to reply....
    i will try to put it in simple terms; say, in excel i have 2 sheets - 1st sheet has [product no] and [SAP document no] columns and 2nd sheet also has same columns plus additional [created date] column.
    My requirement is, in 1st sheet, in the new column i need to get created date from 2nd sheet for which the [product no] is same in both sheets.
    After this for which [product no] is not found in the 2nd sheet i need to give second condition that is check for the [SAP document no] in 2nd sheet, if [SAP document no] is found i want to have " [SAP document no] is available but [product no] is not available" . if it is not found it should give "[SAP document no] is not available" in the new column in 1st sheet.

    not exactly but it may look as below in excel formula; the same i am implementing in Access.
    =IF(ISERROR(VLOOKUP(H7,Sale_Report!$A:$L,1,0)=TRUE ),IF(ISERROR(VLOOKUP(C7),Sale_Report!$O:$O,1,0)=TR UE),"[SAP document no] is not available","[SAP document no] is available but [product no] is not available"),VLOOKUP(H7,Sale_Report!$A:$L,12,0))

    I hope it may give some clarifications....

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

Similar Threads

  1. Replies: 2
    Last Post: 10-14-2014, 12:53 AM
  2. Unable to create shortcut menu
    By lawdy in forum Programming
    Replies: 36
    Last Post: 05-25-2014, 10:36 AM
  3. How to create one report from two queries
    By tanyapeila in forum Reports
    Replies: 4
    Last Post: 03-18-2014, 01:57 PM
  4. Unable to create duplicate record on subform
    By nika.duncan in forum Programming
    Replies: 9
    Last Post: 12-02-2013, 02:26 PM
  5. Unable to create new record in Forms
    By escapades_access in forum Forms
    Replies: 5
    Last Post: 03-16-2011, 03:23 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