I am creating stored procedure in SQL Server 2008. I'm a little confused on how to group a specific column only when it meets the criteria below. Can anyone help? I have notes in the code below. Thanks.

Criteria:
1) @Coverage & @GroupByMain are optional i.e if a null value is passed for these parameters, they must be ignored
2) If @GroupByMain is not null then the column CalculatedSDCash should be grouped by HiNetMajor
------------------------------------------------------------------

CREATE PROCEDURE [dbo].[Sel_DCF_AcctCurrStatusHistory]
@AsOfDate datetime,
@Coverage nvarchar(20),
@GroupByMain nvarchar(4) --Will either be 'MAIN' or NULL
AS
BEGIN
SET NOCOUNT ON;

SELECT *
FROM tblDCF_AcctCurrStatusHistory
WHERE ((@Coverage IS NULL) OR (Coverage = @Coverage))-- AND
--((@GroupByMain IS NULL) OR (@GroupByMain IS NOT NULL AND **Don't know what to do here** ))
GROUP BY
--Not sure how I group "CalculatedSDCash" by "HiNetMajor" only if "GroupByMain" is not null??? And do I sum "CalculatedSDCash"?
END