SQL中的串联列与定界符。如果第一列为null,则不希望定界符在其之后出现。我如何摆脱它?
SELECT TOP 1000 places.*
, home_Desc
, CONCAT_WS(' - ', COALESCE(brand, ' '), home_Desc, location_Desc) AS homeSite
示例:
brand | home_desc | location_desc |
---|---|---|
蓝色 | 大 | 木质 |
零 | 森林 | , |
所以我现在得到:
1.' blue - large - woody '
2. ' - small - forest '
但是第二盘我想要的是:
small - forest
SELECT TOP 1000 places.*
, home_Desc
, CONCAT_WS(' - ', COALESCE(brand, ' '), home_Desc, location_Desc) AS homeSite
Example:
brand | home_Desc | location_Desc |
---|---|---|
blue | large | woody |
NULL | small | forest |
So right now I am getting:
1.' blue - large - woody '
2. ' - small - forest '
But what I want for the second set is:
small - forest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如松鼠所说,您必须将 colesce(品牌,'')替换为品牌
As Squirrel say, you must replace COALESCE(brand, '') to brand
利用该规则,与null值(在本例中为分支)连接的非null值(在这种情况下的仪表符)将产生null(并假设其他两个永远不能为null/blank:
Taking advantage of the rule a non-NULL value (the dash character in this instance) concatenated with a NULL value (branch, in this instance) would yield NULL (and assuming that the other two can never be null/blank: