sql - How can I create a view by passing the name from a parameter? (like: CREATE VIEW @ViewName ) -


How can I use a parameter that stands for the view name that I passed in the CREATE VIEW statement in SQL Can i do

  DECLARE @ViewName VARCHAR (40) = 'V_fooo' Make scene as @ViewName * *  

from food items due to syntax error Does. How can I achieve this? Thank you.

You have to use this dynamic SQL.

  DECLARE @ViewName VARCHAR (40) = 'V_fooo' DECLARE @ SQL VARCHAR (MAX) = 'create the view' + @ViewName + 'from foods as' EXEC (@sQL)  


Comments