Options

SQL Query for multiple companies

SrivasSrivas Member Posts: 89
edited 2012-03-24 in NAV Three Tier
Hi all,

I want to write an SQL query (VIEW) to show Item ledger data from multiple companies (say A,B,C) {same database}
. I don't know how to do it (like including $).

Many Thanks in advance

Comments

  • Options
    ara3nara3n Member Posts: 9,255
    here is an example
    SELECT 
    'Hall Company',"Item No_","Entry Type","Variant Code","Drop Shipment","Location Code","Posting Date",
     COUNT_BIG(*) "$Cnt",SUM("Quantity") "SUM$Quantity",SUM("Invoiced Quantity") "SUM$Invoiced Quantity" 
     FROM dbo."Hall Company$Item Ledger Entry" 
     GROUP BY "Item No_","Entry Type","Variant Code","Drop Shipment","Location Code","Posting Date"
    union
    SELECT
    'Second Company',"Item No_","Entry Type","Variant Code","Drop Shipment","Location Code","Posting Date",
     COUNT_BIG(*) "$Cnt",SUM("Quantity") "SUM$Quantity",SUM("Invoiced Quantity") "SUM$Invoiced Quantity" 
     FROM dbo."Second Company$Item Ledger Entry" 
     GROUP BY "Item No_","Entry Type","Variant Code","Drop Shipment","Location Code","Posting Date"
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    SrivasSrivas Member Posts: 89
    Thanks a million. Is it possible to get flowfields like Cost Amount (actual)..

    Thanks
  • Options
    ara3nara3n Member Posts: 9,255
    yes it is possible
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    krikikriki Member, Moderator Posts: 9,090
    ara3n wrote:
    yes it is possible
    No: not using the table where the flowfield is defined.
    Yes: you need to write the select on the real table (you can also point to the indexed view but that can be dangerous if you change some SIFT).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    ara3nara3n Member Posts: 9,255
    here is an example of getting flowfields
    select [Entry No_], [Item No_], *,
    (SELECT  sum([Cost Amount (Actual)])
    			from [Hall Company$Value Entry] as V 
    			where [Item Ledger Entry No_] =ILE.[Entry No_]) as CostAmountActual
    from	[Hall Company$Item Ledger Entry]	as ILE
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.