gpt4 book ai didi

SQL 服务器 : append string not working if col is empty

转载 作者:行者123 更新时间:2023-12-02 07:26:13 25 4
gpt4 key购买 nike

我需要以编程方式将一些字符串附加到 col1。以下代码仅在 col1 不为空的情况下有效。如果它是空的,那么在运行代码后它仍然是空的。为什么?

UPDATE 
table
SET
col1 = col1 + ';somestring'
WHERE
col2 = rowID

最佳答案

那是因为任何对 NULL 的操作都会导致 NULL。您需要使用 ISNULL() 将您的 NULL 值“转换”为空字符串:

UPDATE 
table
SET
col1 = ISNULL(col1, '') + ';somestring'
WHERE
col2 = rowID

关于SQL 服务器 : append string not working if col is empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31179144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com