locked
one column with break to next line RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my table data

    ArticleCode Color Qty
    A1 Black 2
    A1 Black 4
    A2 Red 5
    A2 Red 10
    A2 Red 15
    C1 Green 6

    I want resultset like this

    Can we have output like below in stuff query

    ArticleCode

    Color

    Qty

    A1

    Black

    2

    4

    A2

    Red

    5

    10

    15

    C1

    Green

    6

    Tuesday, September 10, 2019 10:56 AM

Answers

  • User61956409 posted

    Hi Gopi.MCA,

    You can refer to the following query.

    SELECT ArticleCode, Color, STUFF((
              SELECT char(10) + '                           ' + CAST(t.Qty AS NVARCHAR(MAX))
              FROM ArticleTable t
              WHERE t.ArticleCode = a.ArticleCode AND  t.Color = a.Color
              FOR XML PATH('')), 1,24, '') AS Qty
    FROM ArticleTable a
    GROUP BY ArticleCode, Color

    Results to Text

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 12, 2019 6:11 AM

All replies