我有一张这样的桌子
id data
1 note1
1 note2
3 note6
3 note8
当我从该表中选择数据时,我想将数据列值连接起来,例如
select data
from table
where id = 1 --(this query is just for demonstration )
需要给出类似的输出
note1+note2
有什么办法可以做到这一点?
注意:我曾尝试使用 COALESCE(我从 Vishal 获得),但它也无法正常工作。这就是我的实际查询现在的样子
declare @var1 varchar(200)
SELECT dbo.kt_missingdataview.Varenummer, dbo.kt_missingdataview.Varenavn, dbo.kt_missingdataview.Producentvarenummer,
(SELECT dbo.ETEXT.TXT1
WHERE (dbo.ETEXT.ID = 1)) AS shortdesc,
(SELECT @var1 = COALESCE(@var1 + '+', '') + dbo.ETEXT.TXT1 from dbo.ETEXT
Select @var1),
(SELECT dbo.ETEXT.TXT1
WHERE (dbo.ETEXT.ID = 2)) AS longdesc, dbo.ETEXT.REFKEY, dbo.ETEXT.ID
FROM dbo.kt_missingdataview INNER JOIN
dbo.ETEXT ON dbo.kt_missingdataview.Varenummer = dbo.ETEXT.REFKEY
WHERE (dbo.ETEXT.ELANGUAGE = 0)