zoukankan      html  css  js  c++  java
  • 错误的语法:"create view必须是批处理中仅有的语句"

     编写脚本提示:

    错误的语法:"create view必须是批处理中仅有的语句"

    IF NOT EXISTS ( SELECT  1
                    FROM    sys.views
                    WHERE   name = 'v_CS_UserRoleNames' )
        BEGIN
            CREATE VIEW v_CS_UserRoleNames
            AS
                SELECT  c.UserID AS ur_UserID ,
                        c.LoginID AS ur_LoginID ,
                        c.FullName AS ur_FullName ,
                        c.[Status] AS ur_Status ,
                        c.ZoneID AS ur_ZoneID ,
                        c.OrgID AS ur_OrgID ,
                        c.FactID AS ur_FactID ,
                        ','
                        + STUFF(( SELECT    ',' + b.RoleName
                                            + CAST(b.RoleMajorType AS VARCHAR)
                                  FROM      System_Role b
                                  WHERE     CHARINDEX(','
                                                      + CONVERT(VARCHAR(36), b.RoleID)
                                                      + ',', ',' + c.RoleIDs + ',') > 0
                                FOR
                                  XML PATH('')
                                ), 1, 1, '') + ',' AS ur_RoleNames
                FROM    System_Users c
        END
    
    ELSE
        BEGIN
     
            ALTER VIEW v_CS_UserRoleNames
            AS
                SELECT  c.UserID AS ur_UserID ,
                        c.LoginID AS ur_LoginID ,
                        c.FullName AS ur_FullName ,
                        c.[Status] AS ur_Status ,
                        c.ZoneID AS ur_ZoneID ,
                        c.OrgID AS ur_OrgID ,
                        c.FactID AS ur_FactID ,
                        ','
                        + STUFF(( SELECT    ',' + b.RoleName
                                            + CAST(b.RoleMajorType AS VARCHAR)
                                  FROM      System_Role b
                                  WHERE     CHARINDEX(','
                                                      + CONVERT(VARCHAR(36), b.RoleID)
                                                      + ',', ',' + c.RoleIDs + ',') > 0
                                FOR
                                  XML PATH('')
                                ), 1, 1, '') + ',' AS ur_RoleNames
                FROM    System_Users c
        END 

    create view 必须是批处理中的第一条语句。

    修改为:

    IF NOT EXISTS ( SELECT  1
                    FROM    sys.views
                    WHERE   name = 'v_CS_UserRoleNames' )
        BEGIN
            DROP VIEW v_CS_UserRoleNames
        
        END
    
    go
    CREATE VIEW v_CS_UserRoleNames
    AS
        SELECT  c.UserID AS ur_UserID ,
                c.LoginID AS ur_LoginID ,
                c.FullName AS ur_FullName ,
                c.[Status] AS ur_Status ,
                c.ZoneID AS ur_ZoneID ,
                c.OrgID AS ur_OrgID ,
                c.FactID AS ur_FactID ,
                ','
                + STUFF(( SELECT    ',' + b.RoleName
                                    + CAST(b.RoleMajorType AS VARCHAR)
                          FROM      System_Role b
                          WHERE     CHARINDEX(',' + CONVERT(VARCHAR(36), b.RoleID)
                                              + ',', ',' + c.RoleIDs + ',') > 0
                        FOR
                          XML PATH('')
                        ), 1, 1, '') + ',' AS ur_RoleNames
        FROM    System_Users c
    学习,以记之。如有错漏,欢迎指正

    作者:冯子武
    出处:http://www.cnblogs.com/Zev_Fung/
    本文版权归作者和博客园所有,欢迎转载,转载请标明出处。
    如果博文对您有所收获,请点击下方的 [推荐],谢谢

  • 相关阅读:
    mongoDB--1 概念
    PythonWeb-Django框架学习-Demo2-创建你的小WEB应用
    PythonWeb-Django框架学习-Demo1-快速搭建项目
    Python--Demo18--异步IO之协程
    Python--Demo17--WEB应用程序之模板和MVC
    Python--Demo16--WEB应用程序之框架的好处
    Python--Demo15--WEB应用程序WGSI接口
    快速了解HTTP协议
    Python--Demo14--正则表达式
    Python--Demo13--高级特性匿名函数、推导式、迭代器、生成器
  • 原文地址:https://www.cnblogs.com/Zev_Fung/p/8135737.html
Copyright © 2011-2022 走看看