Some of the code missed after saving

I am writing a code as sql view, after I save the view and reopen it I found that some of the code is missing, so the code doesn't work
Please see the screenshots below
1
2

What might be the issue here?

The tab on the top screenshot has an '*' which means it wasn't saved

You aren't running a CREATE VIEW but instead are running a query using a common table expression(WITH S...).
Please search for CREATE VIEW in BOL or google it.

1 Like

There have always been issues with the view designer in SSMS - as far back as SQL Server 2000 (maybe even earlier).

Don't use this to create your views - just open a new query window and build the statement. If you already have a defined view - you can right-click the view and script as ... to a new query window.