Querying MS SQL Server: Using STUFF Function (Trans-SQL)

preview_player
Показать описание
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!

Рекомендации по теме
Комментарии
Автор

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

hengamely
Автор

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

mrmrjims
welcome to shbcf.ru