Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics RMS (Archived)

SQL Query

Posted on by Microsoft Employee

Mabuhay! Hi! I just wondering why this code doesnt work on SQL but if i run this one in memorized report it will show the query;

SELECT PurchaseOrder.LastUpdated, PurchaseOrder.POTitle, PurchaseOrder.POType, PurchaseOrder.StoreID, PurchaseOrder.ID, PurchaseOrder.PONumber,
PurchaseOrder.DateCreated, PurchaseOrder.[To], PurchaseOrderEntry.ItemDescription, PurchaseOrderEntry.StoreID AS Expr2, PurchaseOrderEntry.ID AS Expr3,
PurchaseOrderEntry.PurchaseOrderID, PurchaseOrderEntry.ItemID, PurchaseOrderEntry.Price, PurchaseOrder.ShipTo, PurchaseOrderEntry.OrderNumber
FROM PurchaseOrder LEFT OUTER JOIN
PurchaseOrderEntry ON PurchaseOrder.ID = PurchaseOrderEntry.PurchaseOrderID
GROUP BY PurchaseOrder.ID, PurchaseOrder.ShipTo, PurchaseOrderEntry.OrderNumber

Error: 

Msg 8120, Level 16, State 1, Line 1
Column 'PurchaseOrder.LastUpdated' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


I would like to run in my DataGridVIew on VIsual Studio application and this error doesnt help me to work on this. Any help guy :).

Thanks,

Chris

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SQL Query

    And this code works

    SELECT     max (PurchaseOrder.LastUpdated), max (PurchaseOrder.POTitle), max (PurchaseOrder.POType), max  (PurchaseOrder.StoreID), max (PurchaseOrder.ID), max (PurchaseOrder.PONumber),

                         max (PurchaseOrder.DateCreated), max (PurchaseOrder.[To]), max (PurchaseOrderEntry.ItemDescription), max (PurchaseOrderEntry.StoreID) AS Expr2,max (PurchaseOrderEntry.ID) AS Expr3,

                        max (PurchaseOrderEntry.PurchaseOrderID), max (PurchaseOrderEntry.ItemID), max (PurchaseOrderEntry.Price), max (PurchaseOrder.ShipTo),max (PurchaseOrderEntry.OrderNumber)

    FROM         PurchaseOrder LEFT OUTER JOIN

                         PurchaseOrderEntry ON PurchaseOrder.ID = PurchaseOrderEntry.PurchaseOrderID

    GROUP BY PurchaseOrder.ID

    just adding the aggregiate code thanks Sir Nicco

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans