so as tigin44 has shown in his example
the answer to your question of "Can I save a VIEW with a declare statement?" is NO, sorry. You will have to replace any references to your @dt1 and @dt2 with the expressions you have in your set statements.

Featured Post

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.