我使用以下查询将文本追加到逗号分隔值的可变长度文本字段的末尾:
UPDATE dbo.Sources
SET CatCustom = RTRIM(CatCustom) + ', LRR01'
WHERE SourceID IN (1,2,3,4,5,8,9,44,63,45,101,102,222,344)我发现许多CatCustom字段都是空的,因此在这些字段中以',LRR01‘结尾--前面的逗号和空格是不可取的。那么,我将如何增强这个查询来说明
> If the CatCustom field is NULL, set it to 'LRR01', else SET CatCustom = RTRIM(CatCustom) + ', LRR01'?发布于 2017-09-05 19:30:44
concat_ws正是您所需要的:
UPDATE dbo.Sources
SET CatCustom = CONCAT_WS(', ', RTRIM(CatCustom), 'LRR01')
WHERE SourceID IN (1,2,3,4,5,8,9,44,63,45,101,102,222,344)https://stackoverflow.com/questions/46062000
复制相似问题