zoukankan      html  css  js  c++  java
  • CREATE VIEW must be the only statement in the batch

    CREATE VIEW must be the only statement in the batch

    Just as the error says, the CREATE VIEW statement needs to be the only statement in the query batch.

    You have two option in this scenario, depending on the functionality you want to achieve:

    1. Place the CREATE VIEW query at the beginning

      CREATE VIEW showing
      as
      select tradename, unitprice, GenericFlag
      from Medicine;
      
      with ExpAndCheapMedicine(MostMoney, MinMoney) as
      (
          select max(unitprice), min(unitprice)
          from Medicine
      )
      ,
      findmostexpensive(nameOfExpensive) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
          where UnitPrice = MostMoney
      )
      ,
      findCheapest(nameOfCheapest) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
              where UnitPrice = MinMoney
          )
      
    2. Use GO after the CTE and before the CREATE VIEW query

      -- Option #2

      with ExpAndCheapMedicine(MostMoney, MinMoney) as
      (
          select max(unitprice), min(unitprice)
          from Medicine
      )
      ,
      findmostexpensive(nameOfExpensive) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
          where UnitPrice = MostMoney
      )
      ,
      findCheapest(nameOfCheapest) as
      (
          select tradename
          from Medicine, ExpAndCheapMedicine
          where UnitPrice = MinMoney
      )
      
      GO    
      
      CREATE VIEW showing
      as
      select tradename, unitprice, GenericFlag
      from Medicine;

     

    Create View的上下都需要加Go,如果上下都有其他sql的话

  • 相关阅读:
    Linux搭建ElasticSearch环境
    从DDD开始说起
    TFS看板晨会
    TFS看板的迭代规划
    TFS看板规则
    TFS看板的设计
    Api容器在应用架构演化中的用途
    基于Abp的WebApi容器
    线程队列
    动态类型序列化
  • 原文地址:https://www.cnblogs.com/chucklu/p/14721105.html
Copyright © 2011-2022 走看看