开发者

Combine results from sql query

开发者 https://www.devze.com 2023-01-08 11:29 出处:网络
I have three tables in sql, CUSTOMER, ISSUE, ISSUE_NOTES. SELECT CUSTOMER.name, ISSUE.description, ISSUE_NOTES.notes

I have three tables in sql, CUSTOMER, ISSUE, ISSUE_NOTES.

SELECT CUSTOMER.name, ISSUE.description, ISSUE_NOTES.notes
FROM  CUSTOMER, ISSUE, ISSUE_NOTES
WHERE CUSTOMER.customer_id = ISSUE.customer_id
AND ISSUE_NOTES.incident_id = ISSUE_NOTES.incident_id

This will produce a row for each issue_notes field that's populated. (field is VARCHAR2(4000)

I want 开发者_开发百科to concatenate the notes field(s) (from the issue_notes table) into one field. (I'm archiving information into another database - this statement will be ran weekly)

The aim being I will have one row with a large notes field being the sum of all text from the above syntax, is this possible?

Thanks.


You can use COALESCE:

Here's a taste for it:

DECLARE @output varchar(1000)
(SELECT @output = COALESCE(@output + ', ', '') + notes FROM ISSUE_NOTES)
SELECT @output
0

精彩评论

暂无评论...
验证码 换一张
取 消