I've written this query, however im not sure it the best way to write it. Could someone please help?
Thanks in advance
Select t1.*
From
(Select Silo,Arrow_Silo_Name, AccountName,Account_Name
From Sales_Matrix inner join Arrow_Silo_Description
on Sales_Matrix.Silo = Arrow_Silo_Description.Arrow_Silo_ID inner join Time_Card_Security
On Sales_Matrix.Silo = Time_Card_Security.Silo_Number
left outer join D_Accounts on Sales_Matrix.AccountName = D_Accounts.Acc_B_Key
Where Sales_Matrix.[YEAR] = @Year
and (@Quarter Is Null Or Sales_Matrix.Quarter_Name = @Quarter)
and (@Month Is NULL or Sales_Matrix.[MONTH] = @Month)
and IS_MEMBER(Time_Card_Security.Active_Directory_Path) = 1
Group by Silo,Arrow_Silo_Name, AccountName,Account_Name)t1
Left outer join
(Select Silo_1,Arrow_Silo_Name, MaginusAccount, Account_Name
from V_TimeCard inner join Time_Card_Security
on V_TimeCard.Silo_1 = Time_Card_Security.Silo_Number inner join Arrow_Silo_Description
On V_TimeCard.Silo_1 = Arrow_Silo_Description.Arrow_Silo_ID
where V_TimeCard.[YEAR] = @Year
and (@Quarter Is Null Or V_TimeCard.[Quarter] = @Quarter)
and (@Month Is NULL or V_TimeCard.[MONTH] = @Month) and Silo_1 not in ('','0','98', '99')
and IS_MEMBER(Time_Card_Security.Active_Directory_Path) = 1
Group by Silo_1, Arrow_Silo_Name,MaginusAccount, Account_Name)t2
on t1.Silo=t2.Silo_1 and t1.AccountName=t2.MaginusAccount
where t2.Silo_1 is null
Thanks in advance
Select t1.*
From
(Select Silo,Arrow_Silo_Name, AccountName,Account_Name
From Sales_Matrix inner join Arrow_Silo_Description
on Sales_Matrix.Silo = Arrow_Silo_Description.Arrow_Silo_ID inner join Time_Card_Security
On Sales_Matrix.Silo = Time_Card_Security.Silo_Number
left outer join D_Accounts on Sales_Matrix.AccountName = D_Accounts.Acc_B_Key
Where Sales_Matrix.[YEAR] = @Year
and (@Quarter Is Null Or Sales_Matrix.Quarter_Name = @Quarter)
and (@Month Is NULL or Sales_Matrix.[MONTH] = @Month)
and IS_MEMBER(Time_Card_Security.Active_Directory_Path) = 1
Group by Silo,Arrow_Silo_Name, AccountName,Account_Name)t1
Left outer join
(Select Silo_1,Arrow_Silo_Name, MaginusAccount, Account_Name
from V_TimeCard inner join Time_Card_Security
on V_TimeCard.Silo_1 = Time_Card_Security.Silo_Number inner join Arrow_Silo_Description
On V_TimeCard.Silo_1 = Arrow_Silo_Description.Arrow_Silo_ID
where V_TimeCard.[YEAR] = @Year
and (@Quarter Is Null Or V_TimeCard.[Quarter] = @Quarter)
and (@Month Is NULL or V_TimeCard.[MONTH] = @Month) and Silo_1 not in ('','0','98', '99')
and IS_MEMBER(Time_Card_Security.Active_Directory_Path) = 1
Group by Silo_1, Arrow_Silo_Name,MaginusAccount, Account_Name)t2
on t1.Silo=t2.Silo_1 and t1.AccountName=t2.MaginusAccount
where t2.Silo_1 is null