here is the sample data with the error message. Many thanks
IF OBJECT_ID('tempdb..#SampleData', N'U') IS NOT NULL
BEGIN
DROP TABLE #SampleData;
END;
SELECT * INTO #SampleData FROM (VALUES
('7425623', '2010-01-01', 'BA', '145', 'CSI','MR JONES', 'R123456', '7425623'),
('7422342', '2017-01-01', 'BA', '145', 'CSI','MR JONES2', 'R123457', '7422342'),
('7414996', '2015-01-01', 'CA', '146', 'WCM','MR JONES3', 'R123458', '7422342'),
('6845684', '2014-01-01', 'BAA', '143', 'WCM','MR JONES4', 'R123459', '6849972'),
('7473550', '2015-01-01', 'BAA', '145', 'WCM','MR JONES5', 'R1234510', '7422342'),
('7425629', '2016-01-01', 'BA', '144', 'CSI','MR JONES6', 'R1234511', '12241914'),
('7425610', '2014-01-01', 'BA', '141', 'CSI','MR JONES7', 'R1234512', '12241915'),
('7425615', '2011-01-01', 'BAA', '140', 'CSI','MR JONES8', 'R1234513', '12241916')
) d (Seq, CREATED, DEALER, OPNUM, ContCode, SALUTE, REGNO, ContSeqNo)
--FIRST TO BRING IN SEQ2 IN A TEMP TABLE
SELECT a.Seq, a.Created, a.Dealer, a.OpNum, a.ContCode, A.Salute, A.REGNO, A.ContSeqNo, x.Seq AS [SEQ2]
FROM #SampleData AS a
CROSS APPLY (
SELECT Seq
FROM #SampleData AS b
WHERE b.ContSeqNo = a.ContSeqNo
AND b.ContCode = 'CSI'
) AS x;
--END OF FIRST TO BRING IN SEQ2 IN A TEMP TABLE
SELECT Q.Dealer, Q.CSISeqNo, Q2.Question, SD.Opnum, CASE SD.ContCode WHEN 'WCM' THEN SD.ContCode ELSE NULL END AS ContCode,
COUNT(*) AS TOTAL
FROM CSIQuestionsLog AS Q
INNER JOIN CSIQuestions AS Q2
ON Q.CSISeqNo = Q2.CSISeqNo
INNER JOIN #SampleData AS SD
ON Q.LogSeqNo = SD.[SEQ2]
WHERE Q.Created >= '2017-12-06'
AND Q.Created < '2017-12-07'
AND Q.Dealer IN ('BA', 'BAA', 'BVW', 'CA', 'CVW', 'MCH', 'NSK')
AND SD.Tran2 NOT IN ('OBE', 'SMS')
GROUP BY Q.Dealer, Q.CSISeqNo, Q2.Question, CASE SD.ContCode WHEN 'WCM' THEN SD.ContCode ELSE NULL END
ORDER BY Q.Dealer, Q2.Question;
DROP TABLE #SampleData;