在一行上串联一列取决于一个id [英] concatenate a column on one line depends on a id
问题描述
我再次遇到一个基本问题:
I've again a basic question :
如果我这样做了:
SELECT DISTINCT id, date, doctext, docline, from documentation where date in (02/14/2017)
$ b的ID,日期,文档文本,文档行$ b
doctext是 char(80)
,我无法更改它。此列的问题是大小,我无法保存一个> 80个字符的值,如果该文档> 80个字符,它将在SQL中保存两行并升级该文档行
doctext is a char(80)
and I cannot change it. The problem of this columns is the size, I cannot save a value > 80 characters, If the doc is > 80 char, it will save two lines in SQL and upgrade the docline
所以我的结果是,例如:
So my result is, for example :
0 2017-02-14 this is a basic test to show you the result 0
1 2017-02-14 this is a new basic test to show you the result 0
2 2017-02-14 this is a long basic test to show you the result 0
2 2017-02-14 when the documentation have multiple lines 1
我想做的是如果结果有多行具有相同ID
的行,则连接doctext因此结果应为:
What I'm trying to do is to concatenate doctext if the result have multiple line with the same id So the result should be :
0 2017-02-14 this is a basic test to show you the result
1 2017-02-14 this is a new basic test to show you the result
2 2017-02-14 this is a long basic test to show you the result when the documentation have multiple lines 1
是否可以在o上连接一列ne行取决于id?
我正在尝试使用CASE,例如:
Is it possible to concatenate a column on one line depends on a id ? I'm trying with CASE like :
CASE WHEN docline > 0 THEN DOCTEXT ...
我不知道如何证明自己想要下一个DOCTEXT
I don't know how can I spectify that I would like the next DOCTEXT
谢谢
推荐答案
类似的东西应该可行
SELECT id, date,MAX(docline),
Ids=Stuff((SELECT ' ' + doctext FROM documentation d WHERE d.id=documentation.id
FOR XML PATH (''))
, 1, 1, '' )
from documentation where date in (02/14/2017)
GROUP BY id,date
这篇关于在一行上串联一列取决于一个id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!