Hi I am trying to join three tables to one main table by using a left join
use [SpierLive] go select /*Item Ledger Entry Table*/ a.[Entry No_], max(a.[Source No_]), max(a.[Global Dimension 1 Code]) as [Brand Class], max(a.[Country_Region Code]) as [Country Code], sum(cast(a.[Quantity] as numeric)) [Quantity], sum(cast(a.[Remaining Quantity] as numeric)) [Remaining Quantity], max(a.[Variant Code]) as [Variant Code], /*Value Entry Table*/ --(b.[Posting Date]), max(b.[Inventory Posting Group]), max(b.[Global Dimension 1 Code] as [Brand Class Code]), sum(cast(b.[Valued Quantity] as numeric)) [Valued Quantity], sum(cast(b.[Sales Amount (Actual)] as numeric)) [Sales Amount (Actual)], sum(cast(b.[Cost Amount (Actual)] as numeric)) [Cost Amount (Actual)], sum(cast(b.[Expected Cost] as numeric)) [Expected Cost], sum(cast(b.[Sales Amount (Expected)] as numeric))[Sales Amount (Expected)], sum(cast(b.[Cost Amount (Expected)] as numeric)) [Cost Amount (Expected)], /*Item Table*/ max(c.[Inventory Posting Group]) as [Inventory Posting Group], max(c.[Item Category Code]) as [Item Category Code], max(c.[Base Unit of Measure]) as [Base Unit of Measure], sum(cast(c.[Unit Cost] as numeric)) [Unit Cost], sum(cast(c.[Standard Cost] as numeric)) [Standard Cost], sum(cast(c.[Last Direct Cost] as numeric)) [Last Direct Cost], /*WineMS Inv_Transaction tbl Table*/ max(d.[Company]) as [Company], sum(cast(d.[Quantity] as numeric)) [Quantity], sum(cast([Cost Amount] as numeric)) [WineMS Cost Amount], max(d.[Brand Group]) as [Brand Group], max(d.[Owner]) as [Owner] from [dbo].[Spier Live$Item Ledger Entry] a, [dbo].[Spier Live$Value Entry] b, [dbo].[Spier Live$Item] c, [dbo].[WineMS Inv_Transaction Tbl] d left join [dbo].[Spier Live$Item Ledger Entry] on a.[Item No_] = c.[No_] left join [dbo].[Spier Live$Value Entry] on b.[Item No_] =c.[No_] left join [dbo].[WineMS Inv_Transaction Tbl] on d.[Item No] = c.[No_] group by a.[Entry No_]
I am getting this error when I execute the script
Msg 4104, Level 16, State 1, Line 32 The multi-part identifier "a.Item No_" could not be bound. Msg 4104, Level 16, State 1, Line 32 The multi-part identifier "c.No_" could not be bound. Msg 4104, Level 16, State 1, Line 33 The multi-part identifier "b.Item No_" could not be bound. Msg 4104, Level 16, State 1, Line 33 The multi-part identifier "c.No_" could not be bound. Msg 4104, Level 16, State 1, Line 34 The multi-part identifier "c.No_" could not be bound. Msg 209, Level 16, State 1, Line 24
if I use a where clause the query runs to long , even though I have a group by entry no, what am I doing wrong.
*This post is locked for comments