select collection_date,Collection_time,Branch_code,company_id,rec_series,receipt_number,FirstSet.receipt,account_number,account_type,collected_amount,agent_code
from (select collection_date,Collection_time,Branch_code,company_id,rec_series,receipt_number,receipt,account_number,account_type,collected_amount,agent_code
from missing where collection_date between '2016-02-19' AND '2016-02-23' and rec_series ='SP18')as FirstSet
inner join
(SELECT TOP 1
receipt + 1
FROM misseddata mo
WHERE NOT EXISTS
(
SELECT NULL
FROM misseddata mi
WHERE mi.receipt = mo.receipt + 1
)
group BY receipt )
What I have tried:
joined two table to get the missing record and getting the error message
( Msg 102, Level 15, State 1, Line 14
Incorrect syntax near ')'. Dont na where i went wrong