Hi,
The query following below differs in execution time on two different systems of same hardware and software configuration -- i.e. 1 second and 39 seconds respectively.
select distinct * from (select sl.Date_Of_Service, sl.SM_ID, sl.Added_to_Queue, c.SA_ID, sl.Remark, wi.Date_Of_Commencement, wi.AMC_Period, wi.Payment_Status, wi.Warranty_Status, wi.Warranty_Type, wi.AMC_Date, wi.Valid_Upto, wi.AMC_Validity, c.Customer_ID,
c.Customer_Name, c.Customer_Address, c.Customer_Phone1, c.Customer_Phone2, sa.SA_Name,sa.File_No, sa.SA_Phone, sa.SA_A_Phone from Service_Log sl inner join Warranty_Info wi on sl.WI_ID=wi.WI_ID join Customers c on wi.Customer_ID=c.Customer_ID join Service_Area
sa on c.SA_ID=sa.SA_ID join Products p on wi.Product_ID=p.Product_ID where MONTH(sl.Date_Of_Service)=Month(CONVERT(date, getdate())) and YEAR(sl.Date_Of_Service)=YEAR(CONVERT(date, getdate())) and sa.File_No='H.29' and wi.Is_Active=1 and p.Product_Name<>'Inverter')
as table1, (SELECT Customer_ID, Date_Of_Commencement, STUFF((SELECT char(10)+'+ ' +char(10) + Pro_Desc FROM (select sl.*, wi.Product_Serial, wi.Date_Of_Commencement, wi.Warranty_Type, wi.AMC_Period, wi.Payment_Status, wi.Warranty_Status, wi.AMC_Date,
wi.Valid_Upto, wi.AMC_Validity, c.Customer_ID, c.Customer_Name, c.Customer_Address, c.Customer_Phone1, c.Customer_Phone2, sa.SA_Name,sa.File_No, sa.SA_Phone, sa.SA_A_Phone, p.Product_ID, p.Product_Name, p.Warranty_Period, p.Pro_Desc from Service_Log sl inner
join Warranty_Info wi on sl.WI_ID=wi.WI_ID join Customers c on wi.Customer_ID=c.Customer_ID join Service_Area sa on c.SA_ID=sa.SA_ID join Products p on wi.Product_ID=p.Product_ID where MONTH(sl.Date_Of_Service)=Month(CONVERT(date, getdate())) and YEAR(sl.Date_Of_Service)=YEAR(CONVERT(date,
getdate()) ) and wi.Is_Active=1 ) r2 WHERE r2.Customer_ID = r1.Customer_ID and r2.Date_Of_Commencement=r1.Date_Of_Commencement FOR XML PATH('')), 2, 3, '') AS Product FROM (select sl.*, wi.Product_Serial, wi.Date_Of_Commencement, wi.Warranty_Type, wi.AMC_Period,
wi.Payment_Status, wi.Warranty_Status, wi.AMC_Date, wi.Valid_Upto, wi.AMC_Validity, c.Customer_ID, c.Customer_Name, c.Customer_Address, c.Customer_Phone1, c.Customer_Phone2, sa.SA_Name,sa.File_No, sa.SA_Phone, sa.SA_A_Phone, p.Product_ID, p.Product_Name, p.Warranty_Period,
p.Pro_Desc from Service_Log sl inner join Warranty_Info wi on sl.WI_ID=wi.WI_ID join Customers c on wi.Customer_ID=c.Customer_ID join Service_Area sa on c.SA_ID=sa.SA_ID join Products p on wi.Product_ID=p.Product_ID where MONTH(sl.Date_Of_Service)=Month(CONVERT(date,
getdate())) and YEAR(sl.Date_Of_Service)=YEAR(CONVERT(date, getdate()) ) and wi.Is_Active=1) r1 GROUP BY r1.Customer_ID, r1.Date_Of_Commencement) as table2 where table1.Customer_ID=table2.Customer_ID and table1.Date_Of_Commencement=table2.Date_Of_Commencement
and table1.Added_to_Queue=1 order by table1.Customer_ID
Can anyone tell me what is the issue...