SQL Views - no variables?

前端 未结 8 1883
北荒
北荒 2020-12-04 17:31

Is it possible to declare a variable within a View? For example:

Declare @SomeVar varchar(8) = \'something\'

gives me the syntax error:

8条回答
  •  抹茶落季
    2020-12-04 17:42

    How often do you need to refresh the view? I have a similar case where the new data comes once a month; then I have to load it, and during the loading processes I have to create new tables. At that moment I alter my view to consider the changes. I used as base the information in this other question:

    Create View Dynamically & synonyms

    In there, it is proposed to do it 2 ways:

    1. using synonyms.
    2. Using dynamic SQL to create view (this is what helped me achieve my result).

提交回复
热议问题