Querying MS SQL Server: Using STUFF Function (Trans-SQL)
Write an SQL query that displays book title, ISBN, and authors for each title.
If there are multiple authors, display them all together in one line,
each name separated by a ‘|’ character.
NOTE: This is similar to concatenating strings, but in this context normal concatenation will not work. Instead, we will use STUFF function to get the desired results.
Learning Microsoft SQL Server? Follow my MS SQL tutorials for beginners. I do a lot of SQL querying challenges and SQL projects as part of my homework – every day!
If you are learning SQL, nothing beats solving real programming exercises and coding challenges.
So don’t forget to subscribe, as I release new programming videos every day!
DOWNLOAD SOURCE FILES:
Nguồn: https://chaoticpharmacology.com/
Xem thêm bài viết khác: https://chaoticpharmacology.com/cong-nghe/
Xem thêm Bài Viết:
- Samsung Galaxy Trend Plus S7580 hard reset
- FPT Shop – Khui hộp Samsung Galaxy Tab 3 V – Tablet tầm trung cho người Việt
- [Review dạo] Đánh giá chi tiết Samsung Galaxy S5 LTE A G906
- HARD RESET S2 HD , E120L , E120K MỞ KHÓA MÀN HÌNH S2HD , HIEU MOBILE
- Tư vấn điện thoại Galaxy Note 5 bây giờ chỉ còn 2 đến 3 triệu liệu có đáng mua không?
If you have SQL Server 2017, check out STRING_AGG
stuff doesn't concatenate, it's the for xml path that do it, stuff is only taking off the first character after you concatenate everything with xml path
i still keep getting error message (SELECT Failed.156: Incorrect syntax near the keyword'FOR'.
select b.Title, b.Id, b.FormId
STUFF ( (SELECT ' | ' + c.Label + ' | '
FROM FormQAC c
join FormsQSA a
on c.QuestionId = a.QuestionId
where b.id = c.QuestionId
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,0,'') as All_value
from FormQ b