August 25, 2020
  • 7:26 am Cách chèn nhạc vào ảnh và video trên Facebook
  • 6:59 am Tóm Tắt The Walking Dead (Xác Sống) | Season 4
  • 6:15 am [Mất gốc Hóa – số 16] – HƯỚNG DẪN CÁCH GỌI TÊN OXIT AXIT – OXIT BAZƠ NHANH THUỘC
  • 5:49 am Cách cài Win từ ổ cứng: cả Win 7/8/8.1 và Win10 (làm mẫu với Win 10)
  • 5:12 am Thủ thuật excel: Cách khóa dữ liệu không cho chỉnh sửa trong excel



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/

admin

RELATED ARTICLES

3 COMMENTS

  1. Swapnil Phulse Posted on July 8, 2020 at 9:34 pm

    If you have SQL Server 2017, check out STRING_AGG

    Reply
  2. Mr Mr Jims Posted on July 8, 2020 at 9:34 pm

    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

    Reply
  3. Heng Amely Posted on July 8, 2020 at 9:34 pm

    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

    Reply
LEAVE A COMMENT