只需将它们添加到外部选择中:
select '"' +
(
SELECT STRING_AGG(TRIM(innerAgg.Result), '" - "')
FROM
(
SELECT DISTINCT
value
FROM STRING_SPLIT(STRING_AGG(t1.[Sample Values], '-'), '-')
) AS innerAgg(Result)
) + '"' as [Sample Values]
from
(
select
'abc' as [Sample Values]
union all
select
'def'
union all
select
'ghi'
) t1
或者在预先形成的位置添加引号
DISTINCT
:
select
(
SELECT STRING_AGG(TRIM(innerAgg.Result), ' - ')
FROM
(
SELECT DISTINCT
CONCAT('"', value, '"')
FROM STRING_SPLIT(STRING_AGG(t1.[Sample Values], '-'), '-')
) AS innerAgg(Result)
) as [Sample Values]
from
(
select
'abc' as [Sample Values]
union all
select
'def'
union all
select
'ghi'
) t1