• flip it around, do IF  dbo.ISOyear(@DatumBegin) >=2018 BEGIN <select from the CTE as written with your SELECT right after> END ELSE BEGIN <your other query> END

    -------------------------------------------------------------------------------------------------------------------------------------
    Please follow Best Practices For Posting On Forums to receive quicker and higher quality responses