Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用以下查询在表中创建以逗号分隔的名称列表
DECLARE @listStr VARCHAR(MAX) SELECT @listStr = COALESCE(@listStr+',' ,'') + Name FROM Production.Product SELECT @listStr
这很好用,但是列表确实包含重复项
任何人都可以建议我如何做到这一点DISTINCT,以便列表不包含重复项。
DISTINCT
有用吗?
DECLARE @listStr VARCHAR(MAX) SELECT @listStr = COALESCE(@listStr+',' ,'') + name FROM (SELECT DISTINCT name FROM Production.Product) t SELECT @listStr