My left join is not working. Can you tell me what is wrong and why I am getting the error msgs below?
error msg:
Msg 4104, Level 16, State 1, Line 23
The multi-part identifier "B.VndNbr" could not be bound.
Msg 4104, Level 16, State 1, Line 21
The multi-part identifier "B.VndNbr" could not be bound.
Msg 4104, Level 16, State 1, Line 21
The multi-part identifier "B.dup_grpid" could not be bound.
Code:
SELECT A.[VndNbr]
,Max(A.[VndName]) As VndName
,Min(A.[InvDt]) As InvDt_Min
,Max(A.[InvDt]) As InvDt_Max
,Sum(A.[AbsGrsInvAmt]) As AbsGrsInvAmt_Sum
,SUM( CASE SIGN(A.NetInvAmt)
WHEN 1 THEN A.NetInvAmt ELSE 0 END ) AS NetInvAmt_Pos,
SUM( CASE SIGN(A.NetInvAmt)
WHEN -1 THEN A.NetInvAmt ELSE 0 END ) AS NetInvAmt_Neg
,Min(A.[ChkDt]) ChkDt_Min
,Max(A.[ChkDt]) ChkDt_Max
-- ,[CliYer]
-- ,[PRGREFNBR]
-- ,[dup_grpid]
,B.Tot_Grps
,COUNT(*) As Tot_Recs
--INTO dbo.Xas_dupK_lst
FROM [KROGER_2010_AP].[dbo].[Xas_dupK] A
LEFT JOIN (Select B.VndNbr, Count(B.dup_grpid) as Tot_Grps
From [KROGER_2010_AP].[dbo].[Xas_dupK]
Group by B.VndNbr ) B
ON A.VndNbr = B.VndNbr
GROUP BY A.VndNbr