I am referring to SQL Server query execution plans to take query cost and then optimize the required things by looking at the plan.
But the total of individual query costs adds up to more than 100%.
This is my query:
DECLARE @date SMALLDATETIME
SELECT Reffd AS NAME
,(
SELECT (
(
SELECT count(*)
FROM [cal_reg].[dbo].[customer]
WHERE upper(Reffd) = upper(main.reffd)
AND cast(DATE AS SMALLDATETIME) = @date
) + (
SELECT count(*)
FROM [cal_reg].[dbo].[rep]
WHERE upper(Reffd) = upper(main.Reffd)
AND cast(DATE AS SMALLDATETIME) = @date
)
)
) AS Completed
,(
SELECT (
(
SELECT count(*)
FROM [cal_reg].[dbo].[customer]
WHERE upper([call Attnd]) = upper(main.[Reffd])
AND cast(DATE AS SMALLDATETIME) = @date
) + (
SELECT count(*)
FROM [cal_reg].[dbo].[rep]
WHERE upper([Call Attnd]) = upper(main.reffd)
AND cast(DATE AS SMALLDATETIME) = @date
)
)
) AS Attended
,(
SELECT (
(
SELECT (
(
SELECT count(*)
FROM [cal_reg].[dbo].[customer]
WHERE upper(Reffd) = upper(main.reffd)
AND cast(DATE AS SMALLDATETIME) = @date
) + (
SELECT count(*)
FROM [cal_reg].[dbo].[rep]
WHERE upper(Reffd) = upper(main.Reffd)
AND cast(DATE AS SMALLDATETIME) = @date
)
)
)
) + (
SELECT (
(
SELECT count(*)
FROM [cal_reg].[dbo].[customer]
WHERE upper([call Attnd]) = upper(main.[Reffd])
AND cast(DATE AS SMALLDATETIME) = @date
) + (
SELECT count(*)
FROM [cal_reg].[dbo].[rep]
WHERE upper([Call Attnd]) = upper(main.reffd)
AND cast(DATE AS SMALLDATETIME) = @date
)
)
)
) AS Total
,'' AS f6row
,'' AS f8row
FROM [cal_reg].[dbo].[customer] AS main
WHERE cast(DATE AS SMALLDATETIME) = @date
AND upper(reffd) IN (
SELECT upper(shname)
FROM common.dbo.Password_table
)
GROUP BY reffd
And for that I am getting total of 104% as shown below:
My question is it possible to solve that more than 100% cost error or are there any other ways from which I can tell my query is running efficiently ?