【问题标题】:Using Case statement within update clause - Sybase在更新子句中使用 Case 语句 - Sybase
【发布时间】:2013-03-01 23:49:32
【问题描述】:

以下是sybase代码。有人可以看看以下是否正确。我想我错过了某处的语法

    declare @test  varchar(32)
    select @test="/data/dump/team/"

    update link
    set link.value=
     case when @test=substring(link.value,1,17)
                   then @test
          when  @test != substring(link.value,1,17)
                      value
    end 
    where link.value != ""
    and link_id=0 and row_id = 462135

因为它给我以下错误:“第 10 行的关键字结尾附近的语法不正确。”

请有人帮我语法。

【问题讨论】:

    标签: sql sql-update case


    【解决方案1】:

    尝试在第二种情况下添加“then”:

    declare @test  varchar(32)
        select @test="/data/dump/team/"
    
        update link
        set link.value=
         case when @test=substring(link.value,1,17)
                       then @test
              when  @test != substring(link.value,1,17)
                       then value
        end 
    

    【讨论】:

    • 谢谢,这就是我错过的......为什么我的眼睛没有发现那个嗯嗯!还在想..还是谢谢..
    【解决方案2】:

    为什么不简单地为第二个“when”做一个“else”?

    【讨论】:

    • 请评论相应的答案作为建议。不要添加为单独的答案
    猜你喜欢
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多