• 在SQL2005/SQL2008中CTE用法差异


    --SQL2008中执行成功

    SELECT @@version 
    /*
    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)   Apr  2 2010 15:48:46   Copyright (c) Microsoft Corporation  Data Center Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: ) (Hypervisor) 
    */
    IF 1>0
    	WITH c
    	AS
    	(
    	SELECT 1 AS ID)
    	SELECT * FROM c
    	
    	


    --SQL2005中执行相同语句时出错

    SELECT @@VERSION
    /*
    Microsoft SQL Server 2005 - 9.00.5000.00 (Intel X86)   Dec 10 2010 10:56:29   Copyright (c) 1988-2005 Microsoft Corporation  Enterprise Edition on Windows NT 6.1 (Build 7600: ) 
    */
    
    IF 1>0
    	WITH c
    	AS
    	(
    	SELECT 1 AS ID)
    	SELECT * FROM c
    /*
    消息 319,级别 15,状态 1,第 2 行
    关键字 'with' 附近有语法错误。如果此语句是公用表表达式或 xmlnamespaces 子句,那么前一个语句必须以分号结尾。
    
    */
    
    --改为
    IF 1>0
    BEGIN
    	WITH c
    	AS
    	(
    	SELECT 1 AS ID)
    	SELECT * FROM c
    END
    



  • 相关阅读:
    load custom class in drupal 8
    HEAD in Git
    composer version constraint 版本号前缀
    如何测试
    看待一段数据
    创建一个plugin
    eclipse的快捷方式
    .git文件夹的猜想
    本地可以但远程不行
    方法点不进去的原因
  • 原文地址:https://www.cnblogs.com/Roy_88/p/5463055.html
Copyright © 2020-2023  润新知