假设我在 SQL Server 中有这样一张表:
Id City Province Country
1 Vancouver British Columbia Canada
2 New York null null
3 null Adama null
4 null null France
5 Winnepeg Manitoba null
6 null Quebec Canada
7 Seattle null USA
我该如何获取查询结果,使得位置是城市、省份和国家以", "分隔的连接,同时省略空值。我希望确保不会有尾随逗号、前导逗号或空字符串出现。例如:
Id Location
1 Vancouver, British Columbia, Canada
2 New York
3 Adama
4 France
5 Winnepeg, Manitoba
6 Quebec, Canada
7 Seattle, USA