Creating a View using stored procedure

前端 未结 3 1949
抹茶落季
抹茶落季 2020-12-07 05:16

This questions have asked few times before, unfortunately I did not get an answer to my questions.

Well I have two SQL (SQL SERVER 2008) tables, Emp

3条回答
  •  执念已碎
    2020-12-07 05:35

    If you want to create a view from within a SP you need to use dynamic SQL.

    Something like this.

    create procedure ProcToCreateView 
    as
    exec ('create view MyView as select 1 as Col')
    

    The create view... code has to be sent as a string parameter to exec and by the looks of it you already have the code you need for the view so just embed it in between the '.

    I really have no idea why you need that. Perhaps you just need to know how to use a view from a SP

    create procedure ProcToUseView
    as
    select Col
    from MyView
    

提交回复
热议问题