Mine got no brackets its shown below. The third ResultDate >= ?, I have added it manually using the CommandText as you have told. I have also added another Param but how to I modify the Fuction (I need to add another param) ? Since i am not using the wizard.
SELECT A.AccountID, A.Name, A.AccountTypeID, A.CompanyTypeID, A.IndustryID, A.AnnualRevenue, A.NoOfEmployee, COALESCE (O.Amount, 0) AS Amount,
COALESCE (O.SecuredCount, 0) AS SecuredCount, CAST(Book.BookCount / Bill.BillCount AS Decimal) AS B2BRatio
FROM Account AS A LEFT OUTER JOIN
(SELECT AccountID, SUM(Amount) AS Amount, COUNT(1) AS SecuredCount
FROM Opportunity
WHERE (Result = 'S') AND (ResultDate >= ?) AND (ResultDate <= ?)
GROUP BY AccountID) AS O ON A.AccountID = O.AccountID LEFT OUTER JOIN
(SELECT AccountID, COUNT(1) AS BookCount
FROM Opportunity AS Opportunity_2
WHERE (NOT (PONo IS NULL)) AND (ResultDate >= ?)
GROUP BY AccountID) AS Book ON A.AccountID = Book.AccountID LEFT OUTER JOIN
(SELECT AccountID, COUNT(1) AS BillCount
FROM Opportunity AS Opportunity_1
WHERE (NOT (DONo IS NULL))
GROUP BY AccountID) AS Bill ON A.AccountID = Bill.AccountID