I'm trying to alter the view below:
ALTER VIEW [dbo].[Win.v_TodayMin365]
AS
    declare @tblOut table(Dates Date)
    declare @cnt INT = -365
    while @cnt < 0
    Begin
            set @cnt = @cnt + 1;
            insert into @tblOut (Dates) values(cast(dateadd(day,@cnt,getdate()) as Date))
    END
    select * from @tblOut
    deallocate @tblOut
    deallocate @cnt
GO
The code as such works (if I highlight all between AS and GO and hit Execute, I get the expected output), but I can't run it as ALTER VIEW. Then, I get the following error:
Incorrect syntax near the keyword 'declare'. Expecting '(', SELECT or WITH
Thanks in advance for any idea!
 
     
    