Hi @SVA
When the procedure is compiled, the columns do not exist, which means adding IsOn is in the same batch as the reference to use IsOn. That is why you got this error.
You could use dynamic SQL for that or split them in two procedures.
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".