Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query help

Status
Not open for further replies.

NotSQL

Technical User
May 17, 2005
205
GB
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
 
You might want to give somemore details about what the problem is and what you would like it to do.

Simi
 
I was just wondering if this was the best way to write the query...
 
What is your SQL Server version? Do you need all fields in the result (including the ones that repeat)?

If you're using SQL Server 2005 or up, I'd move the common part as cte.

PluralSight Learning Library
 
SQL Server 2008R2..... I only require the the records from t1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top