Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

SQL Query Performance

Posted on by Microsoft Employee

Good day all

I am joining Navision tables to get a certain result

firstly I am analyzing the values in the value entry table for a specific customer in NAV vs my OLAP Cube report and the values do match , my analysis will be done in Tableau later.

So in order for me to get the Sales Invoice Line and Sales Cr_Memo data together I have inserted the data from both tables into one SQL table. Then I took the customer table and Value entry table to join to the new table I have created , however my query runs very long , how can I optimize the query to run faster in less time

SELECT 
  [Spier Live$Value Entry].[Posting Date] AS [Posting Date],
  [Spier Live$Value Entry].[Inventory Posting Group] AS [Inventory Posting Group],
  [Spier Live$Value Entry].[Invoiced Quantity] AS [Invoiced Quantity],
  [Spier Live$Value Entry].[Cost per Unit] AS [Cost per Unit],
  [Spier Live$Value Entry].[Sales Amount (Actual)] AS [Sales Amount (Actual)],
  [Spier Live$Value Entry].[Salespers__Purch_ Code] AS [Salespers__Purch_ Code],
  [Spier Live$Value Entry].[Discount Amount] AS [Discount Amount],
  [Spier Live$Value Entry].[Global Dimension 1 Code] AS [Brand Class Code],
  [Spier Live$Value Entry].[Cost Amount (Actual)] AS [Cost Amount (Actual)],
  [Spier Live$Value Entry].[Expected Cost] AS [Expected Cost],
  [Spier Live$Value Entry].[Item Charge No_] AS [Item Charge No_],
  [Spier Live$Value Entry].[Sales Amount (Expected)] AS [Sales Amount (Expected)],
  [Spier Live$Value Entry].[Cost Amount (Expected)] AS [Cost Amount (Expected)],
  [Spier Live$Value Entry].[Variant Code] AS [Variant Code],

  [Sales Invoice_CrMemo Tbl].[Sell-to Customer No_] AS [Sell-to Customer No_],
  [Sales Invoice_CrMemo Tbl].[Posting Group] AS [Posting Group],
  [Sales Invoice_CrMemo Tbl].[Shipment Date] AS [Shipment Date],
  [Sales Invoice_CrMemo Tbl].[Product Group Code] AS [Product Group Code],

  [Spier Live$Customer].[Name] AS [Name],
  [Spier Live$Customer].[City] AS [City],
  [Spier Live$Customer].[Currency Code] AS [Currency Code],
  [Spier Live$Customer].[Shipment Method Code] AS [Shipment Method Code],
  [Spier Live$Customer].[Country_Region Code] AS [Country Code],
  [Spier Live$Customer].[Excise Location] AS [Excise Location]
 
FROM [dbo].[Sales Invoice_CrMemo Tbl] [Sales Invoice_CrMemo Tbl]
  LEFT JOIN [dbo].[Spier Live$Value Entry] [Spier Live$Value Entry] ON ([Spier Live$Value Entry].[Item No_] = [Sales Invoice_CrMemo Tbl].[No_]) 
  LEFT JOIN [dbo].[Spier Live$Customer] [Spier Live$Customer] ON ([Sales Invoice_CrMemo Tbl].[Sell-to Customer No_] = [Spier Live$Customer].[No_])


*This post is locked for comments

  • Suggested answer
    Alex A Profile Picture
    Alex A 2,348 on at
    RE: SQL Query Performance

    Hi Jason, you'll need to better define the join between [Sales Invoice_CrMemo Tbl] and [Spier Live$Value Entry]. If you just try to only join them on Item No then you'll have an inaccurate result (and long wait while it tries to join in every possible way).

    You should be able to nail down an exact join line by line between the Value Entry table and the Sales Invoice_Cr Memo table by seeking to match at least the Document No, Document Line No, and the Item No in your ON statement.

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

    Add Document No_ Filter in the query. It should be like this.

    Select XXXXXX

    FROM [dbo].[Sales Invoice_CrMemo Tbl] [Sales Invoice_CrMemo Tbl]

     LEFT JOIN [dbo].[Spier Live$Value Entry] [Spier Live$Value Entry]

     ON ([Spier Live$Value Entry].[Item No_] = [Sales Invoice_CrMemo Tbl].[No_])

     AND ([Spier Live$Value Entry].[Document No_] = [Sales Invoice_CrMemo Tbl].[Document No_])

    LEFT JOIN [dbo].[Spier Live$Customer] [Spier Live$Customer] ON ([Sales Invoice_CrMemo Tbl].[Sell-to Customer No_] = [Spier Live$Customer].[No_])

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans