I'm trying to create a dynamic sql statement because the where clause can
change depending on certain parameters. I was able to get it to work with
out the grouping clause added. I do not know what I am doing wrong. Any
help would be appreciated.
Thanks in advance

/***********CODE*****************/
DECLARE @SQL NVARCHAR(500)
DECLARE @param NVARCHAR(500)
DECLARE @param2 NVARCHAR(500)
DECLARE @paramPeriod int
DECLARE @paramOrder int

SET @SQL = N'SELECT DISTINCT com_customer_number ' + CHAR(13)
SET @SQL = @SQL + N'FROM dssrepository..tbl_first_shipment ' + CHAR(13)
SET @SQL = @SQL + N'WHERE com_first_ship_period <= @period' + CHAR(13)
SET @SQL = @SQL + N'GROUP BY com_customer_number' + CHAR(13)
SET @SQL = @SQL + N'HAVING COUNT(com_customer_number) = @orders'
SET @param = N'@period int'
SET @paramPeriod = 200012
SET @param2 = N'@orders int'
SET @paramOrder = 1

EXEC sp_executesql @SQL, @param, @period = @paramPeriod, @orders = @paramOrder