I am new to SQL. I am trying to convert a query to use parameters picked up from the Excel sheet. I have made parameter input to work with other queries but this one is fighting hard I have tried all sorts of options, some still in the code and get various error messages including Invalid Columns, "No column name was specified for column of R"


DECLARE @StartDate  DATETime, @EndDate  datetime 

SELECT	DISTINCT A.AccountNumber,
	AccountName AS 'Name', 
	COALESCE(R.SumAc,0) AS 'Total'

FROM 	qryNLSLPLPostedTrans as A 
LEFT JOIN
(
SELECT	AccountNumber, 
	SUM(GoodsValueInBaseCurrency) AS 'SumAc'

FROM	qryNLSLPLPostedTrans

 WHERE	TransactionDate BETWEEN [@StartDate] AND [@EndDate] 

/* WHERE	TransactionDate BETWEEN [] AND [] */


GROUP BY AccountNumber
) as R

ON		A.AccountNumber=R.AccountNumber

ORDER BY	AccountNumber, AccountName
Where have I gone wrong ?
I am using variables to make the queries as generic as possible.

Thanks for any help