Results 1 to 6 of 6
  1. #1
    SAugsburger is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    6

    Cross Apply queries in Acces?

    I wrote a cross apply query in the SQL Management Studio that works how I want it in SSMS, but I can't seem to reproduce a similar query via an access query. The SQL query is below. How would I structure a similar functioned query in access.



    Code:
    SELECT TOP 100000
    SUM(a.[QTY]) AS QTY,
    a.[MFGPN],
    c.[MANUFACTURER],
    c.[DATECODE],
    c.[DESCRIPTION],
    c.[last_mod]
    FROM [DEV].[dbo].[part] a
    CROSS APPLY (SELECT TOP 1 * FROM [post].[dbo].[part] b WHERE a.[MFGPN] = b.[MFGPN]) c
    GROUP BY a.[MFGPN],
    c.[MANUFACTURER],
    c.[DATECODE],
    c.[DESCRIPTION],
    c.last_mod

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What is a cross apply query? Show sample of source data and desired output.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    SAugsburger is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    6
    The sample SQL query is above. Here is an explanation of cross apply:

    http://sqlserverplanet.com/sql-2005/cross-apply-explained

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I saw the SQL and found that information already. Didn't help me understand what you want. A sample of raw data and sample of desired output would be more helpful to clarify what you want to do.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    SAugsburger is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    6
    Here would be a test input

    QTY,MFGPN,MANUFACTURER,DATECODE,DESCRIPTION
    5,Foo,foo,09,test
    6,foo,abc,10,test
    10,foo2,ooo,09,z
    2,foo,zyx,,zy

    Output should obviously sum the QTY field and select the first field


    QTY,MFGPN,MANUFACTURER,DATECODE,DESCRIPTION
    13,Foo,foo,09,test
    10,foo2,ooo,09,z

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    This appears to aggregate data by the MFGPN field but shows the MANUFACTURER, DATECODE, DESCRIPTION from the first record of each MFGPN group. Why the first record? How is showing details of one record with group aggregate data meaningful?

    Will there be a need to filter the records?

    This might get you what you want. However, First and Last aggregate functions can produce unexpected results. Can't always count on the record you think is 'first' or 'last' in table or query to actually be the first or last record.

    SELECT Query2.SumOfQTY, Query2.MFGPN, Query1.FirstOfMANUFACTURER, Query1.FirstOfDATECODE, Query1.FirstOfDESCRIPTION
    FROM (SELECT Table1.MFGPN, First(Table1.MANUFACTURER) AS FirstOfMANUFACTURER, First(Table1.DATECODE) AS FirstOfDATECODE, First(Table1.DESCRIPTION) AS FirstOfDESCRIPTION FROM Table1 GROUP BY Table1.MFGPN) As Query1 INNER JOIN (SELECT Table1.MFGPN, Sum(Table1.QTY) AS SumOfQTY
    FROM Table1 GROUP BY Table1.MFGPN) AS Query2 ON Query1.MFGPN = Query2.MFGPN;
    Last edited by June7; 04-14-2014 at 06:30 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 03-27-2014, 07:15 AM
  2. Cross Queries
    By zminek21 in forum Queries
    Replies: 4
    Last Post: 11-04-2013, 06:47 AM
  3. Combining Results of Cross Tab Queries
    By kkyork in forum Queries
    Replies: 4
    Last Post: 06-06-2012, 09:10 AM
  4. Cross Tab Queries
    By Nixx1401 in forum Access
    Replies: 6
    Last Post: 02-16-2010, 11:55 AM
  5. acces listbox hatası(acces debug)
    By carso in forum Access
    Replies: 1
    Last Post: 09-22-2009, 04:11 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