concatenate rows for many conditionsHow to concatenate text from multiple rows into a single text string in SQL server?How can I remove duplicate rows?Best way to get identity of inserted row?T-SQL: Selecting rows to delete via joinsInserting multiple rows in a single SQL query?SQL Server: How to Join to first rowConcatenate multiple xml columntype rows in SQLHow to select only the first rows for each unique value of a columnSQL Select, selecting a row off of a column conditionConvert row into concatenated string with column names includedSQL Server. SELECT rows by newest column values

Use chown -R while excluding one or two files

How can the electric potential be zero at a point where the electric field isn't, if that field can give a test charge kinetic energy?

How to create array of references?

Was Jacobi the first to notice the ambiguity in the partial derivatives notation? And did anyone object to his fix?

Why do so many pure math PhD students drop out or leave academia, compared to applied mathematics PhDs?

A verb to describe specific positioning of three layers

Is the purpose of sheet music to be played along to? Or a guide for learning and reference during playing?

Did Voldemort kill his father before finding out about Horcruxes?

Why does Eliyahu appear at a brit milah?

How can I design a continuous player experience in a setting that's likely to favor TPKs?

Optimising the Selection of MaxValue in Association

Is this Android phone Android 9.0 or Android 6.0?

Alphanumeric Line and Curve Counting

How to color a tag in a math equation?

Why is Google approaching my VPS machine?

How to remove the first colon ':' from a timestamp?

How Can I Process Untrusted Data Sources Securely?

How could a medieval fortress manage large groups of migrants and travelers?

Movie where a man was put into a computer before death, wife doesn't trust him anymore

What happens if a company buys back all of its shares?

Is this artwork (used in a video game) real?

How to honestly answer questions from a girlfriend like "How did you find this place" without giving the impression I'm always talking about my exes?

Is it okay for a chapter's POV to shift as it progresses?

Is there an English equivalent for "Les carottes sont cuites", while keeping the vegetable reference?



concatenate rows for many conditions


How to concatenate text from multiple rows into a single text string in SQL server?How can I remove duplicate rows?Best way to get identity of inserted row?T-SQL: Selecting rows to delete via joinsInserting multiple rows in a single SQL query?SQL Server: How to Join to first rowConcatenate multiple xml columntype rows in SQLHow to select only the first rows for each unique value of a columnSQL Select, selecting a row off of a column conditionConvert row into concatenated string with column names includedSQL Server. SELECT rows by newest column values






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















i need to concatenate the rows(taille). for exemple , for the code_commande 001 and code_article=1 , i need to concatenate in list all taille wich have this two conditions. another exemple , for code_commande=001 and code_article=2, the same job i need to concatenate in a list all taille wich have this two condition. this for all




code_commande code_article taille
001 1 s
001 1 m
001 1 xl
001 1 x52
001 2 m
001 1 5566
001 2 x52
001 1 xl
002 1 s
002 2 m
001 3 xxl
002 3 xs
001 1 ml
001 1 xs32


I need to concatenate taille for each code_commande for each code_article
exemple of result:




001 1 s,m,xl etcc


dynamicaly



I should have a table who grouped the ( taille) for each code_commande for each code_article like:

001 1 s,m,xl,
001 2 s,xl,l
002 1 xs,ettcc
i have tried this query but ,it concatenate all (taille) for all rows
the query



Select [code_commande],[code_article], SUBSTRING(
(
SELECT ',' +[taille] AS 'data()'
FROM [dbo].[commande] FOR XML PATH('')
), 2 , 9999) As taille_commande
from [dbo].[commande]
order by [code_article],[code_commande]desc










share|improve this question
























  • Explain what you have done and why it does not work.

    – ceving
    Mar 26 at 9:10











  • i need to have table that's have all (tailles) ordered by code_commande and code article exemple : for code_commande 1 and code_article 1 i need have all tailles concatenated and for code_commande 1 and article 2 i need have all tailles etttc

    – user11186153
    Mar 26 at 9:14












  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask. Sample data is best served as DDL + DML. Please edit your question to include it, your current attempt and your desired results. For more details, read this.

    – Zohar Peled
    Mar 26 at 9:16











  • i need a query who returns this

    – user11186153
    Mar 26 at 9:17











  • Well I need a brand new Ferrari. Think we can trade? Stackoverflow is not a free coding service. You are expected to show your efforts at solving the problem at hand.

    – Zohar Peled
    Mar 26 at 9:18

















0















i need to concatenate the rows(taille). for exemple , for the code_commande 001 and code_article=1 , i need to concatenate in list all taille wich have this two conditions. another exemple , for code_commande=001 and code_article=2, the same job i need to concatenate in a list all taille wich have this two condition. this for all




code_commande code_article taille
001 1 s
001 1 m
001 1 xl
001 1 x52
001 2 m
001 1 5566
001 2 x52
001 1 xl
002 1 s
002 2 m
001 3 xxl
002 3 xs
001 1 ml
001 1 xs32


I need to concatenate taille for each code_commande for each code_article
exemple of result:




001 1 s,m,xl etcc


dynamicaly



I should have a table who grouped the ( taille) for each code_commande for each code_article like:

001 1 s,m,xl,
001 2 s,xl,l
002 1 xs,ettcc
i have tried this query but ,it concatenate all (taille) for all rows
the query



Select [code_commande],[code_article], SUBSTRING(
(
SELECT ',' +[taille] AS 'data()'
FROM [dbo].[commande] FOR XML PATH('')
), 2 , 9999) As taille_commande
from [dbo].[commande]
order by [code_article],[code_commande]desc










share|improve this question
























  • Explain what you have done and why it does not work.

    – ceving
    Mar 26 at 9:10











  • i need to have table that's have all (tailles) ordered by code_commande and code article exemple : for code_commande 1 and code_article 1 i need have all tailles concatenated and for code_commande 1 and article 2 i need have all tailles etttc

    – user11186153
    Mar 26 at 9:14












  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask. Sample data is best served as DDL + DML. Please edit your question to include it, your current attempt and your desired results. For more details, read this.

    – Zohar Peled
    Mar 26 at 9:16











  • i need a query who returns this

    – user11186153
    Mar 26 at 9:17











  • Well I need a brand new Ferrari. Think we can trade? Stackoverflow is not a free coding service. You are expected to show your efforts at solving the problem at hand.

    – Zohar Peled
    Mar 26 at 9:18













0












0








0








i need to concatenate the rows(taille). for exemple , for the code_commande 001 and code_article=1 , i need to concatenate in list all taille wich have this two conditions. another exemple , for code_commande=001 and code_article=2, the same job i need to concatenate in a list all taille wich have this two condition. this for all




code_commande code_article taille
001 1 s
001 1 m
001 1 xl
001 1 x52
001 2 m
001 1 5566
001 2 x52
001 1 xl
002 1 s
002 2 m
001 3 xxl
002 3 xs
001 1 ml
001 1 xs32


I need to concatenate taille for each code_commande for each code_article
exemple of result:




001 1 s,m,xl etcc


dynamicaly



I should have a table who grouped the ( taille) for each code_commande for each code_article like:

001 1 s,m,xl,
001 2 s,xl,l
002 1 xs,ettcc
i have tried this query but ,it concatenate all (taille) for all rows
the query



Select [code_commande],[code_article], SUBSTRING(
(
SELECT ',' +[taille] AS 'data()'
FROM [dbo].[commande] FOR XML PATH('')
), 2 , 9999) As taille_commande
from [dbo].[commande]
order by [code_article],[code_commande]desc










share|improve this question
















i need to concatenate the rows(taille). for exemple , for the code_commande 001 and code_article=1 , i need to concatenate in list all taille wich have this two conditions. another exemple , for code_commande=001 and code_article=2, the same job i need to concatenate in a list all taille wich have this two condition. this for all




code_commande code_article taille
001 1 s
001 1 m
001 1 xl
001 1 x52
001 2 m
001 1 5566
001 2 x52
001 1 xl
002 1 s
002 2 m
001 3 xxl
002 3 xs
001 1 ml
001 1 xs32


I need to concatenate taille for each code_commande for each code_article
exemple of result:




001 1 s,m,xl etcc


dynamicaly



I should have a table who grouped the ( taille) for each code_commande for each code_article like:

001 1 s,m,xl,
001 2 s,xl,l
002 1 xs,ettcc
i have tried this query but ,it concatenate all (taille) for all rows
the query



Select [code_commande],[code_article], SUBSTRING(
(
SELECT ',' +[taille] AS 'data()'
FROM [dbo].[commande] FOR XML PATH('')
), 2 , 9999) As taille_commande
from [dbo].[commande]
order by [code_article],[code_commande]desc







tsql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 9:15







user11186153

















asked Mar 26 at 9:04









user11186153user11186153

11 bronze badge




11 bronze badge












  • Explain what you have done and why it does not work.

    – ceving
    Mar 26 at 9:10











  • i need to have table that's have all (tailles) ordered by code_commande and code article exemple : for code_commande 1 and code_article 1 i need have all tailles concatenated and for code_commande 1 and article 2 i need have all tailles etttc

    – user11186153
    Mar 26 at 9:14












  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask. Sample data is best served as DDL + DML. Please edit your question to include it, your current attempt and your desired results. For more details, read this.

    – Zohar Peled
    Mar 26 at 9:16











  • i need a query who returns this

    – user11186153
    Mar 26 at 9:17











  • Well I need a brand new Ferrari. Think we can trade? Stackoverflow is not a free coding service. You are expected to show your efforts at solving the problem at hand.

    – Zohar Peled
    Mar 26 at 9:18

















  • Explain what you have done and why it does not work.

    – ceving
    Mar 26 at 9:10











  • i need to have table that's have all (tailles) ordered by code_commande and code article exemple : for code_commande 1 and code_article 1 i need have all tailles concatenated and for code_commande 1 and article 2 i need have all tailles etttc

    – user11186153
    Mar 26 at 9:14












  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask. Sample data is best served as DDL + DML. Please edit your question to include it, your current attempt and your desired results. For more details, read this.

    – Zohar Peled
    Mar 26 at 9:16











  • i need a query who returns this

    – user11186153
    Mar 26 at 9:17











  • Well I need a brand new Ferrari. Think we can trade? Stackoverflow is not a free coding service. You are expected to show your efforts at solving the problem at hand.

    – Zohar Peled
    Mar 26 at 9:18
















Explain what you have done and why it does not work.

– ceving
Mar 26 at 9:10





Explain what you have done and why it does not work.

– ceving
Mar 26 at 9:10













i need to have table that's have all (tailles) ordered by code_commande and code article exemple : for code_commande 1 and code_article 1 i need have all tailles concatenated and for code_commande 1 and article 2 i need have all tailles etttc

– user11186153
Mar 26 at 9:14






i need to have table that's have all (tailles) ordered by code_commande and code article exemple : for code_commande 1 and code_article 1 i need have all tailles concatenated and for code_commande 1 and article 2 i need have all tailles etttc

– user11186153
Mar 26 at 9:14














Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask. Sample data is best served as DDL + DML. Please edit your question to include it, your current attempt and your desired results. For more details, read this.

– Zohar Peled
Mar 26 at 9:16





Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask. Sample data is best served as DDL + DML. Please edit your question to include it, your current attempt and your desired results. For more details, read this.

– Zohar Peled
Mar 26 at 9:16













i need a query who returns this

– user11186153
Mar 26 at 9:17





i need a query who returns this

– user11186153
Mar 26 at 9:17













Well I need a brand new Ferrari. Think we can trade? Stackoverflow is not a free coding service. You are expected to show your efforts at solving the problem at hand.

– Zohar Peled
Mar 26 at 9:18





Well I need a brand new Ferrari. Think we can trade? Stackoverflow is not a free coding service. You are expected to show your efforts at solving the problem at hand.

– Zohar Peled
Mar 26 at 9:18












1 Answer
1






active

oldest

votes


















0














As mentioned, STRING_AGG() is your friend for this requirement. Assuming your original post contained the schema you're working with, a simple aggregate query will give you the results you want.



select code_commande, code_article, STRING_AGG(taille, ',') as taille_commande
from dbo.commande
group by code_commande, code_article


STRING_AGG reference



Note this is only available in SQL Server 2017+ and azure. To see a possible solution for previous versions, see this duplicate.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353275%2fconcatenate-rows-for-many-conditions%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As mentioned, STRING_AGG() is your friend for this requirement. Assuming your original post contained the schema you're working with, a simple aggregate query will give you the results you want.



    select code_commande, code_article, STRING_AGG(taille, ',') as taille_commande
    from dbo.commande
    group by code_commande, code_article


    STRING_AGG reference



    Note this is only available in SQL Server 2017+ and azure. To see a possible solution for previous versions, see this duplicate.






    share|improve this answer



























      0














      As mentioned, STRING_AGG() is your friend for this requirement. Assuming your original post contained the schema you're working with, a simple aggregate query will give you the results you want.



      select code_commande, code_article, STRING_AGG(taille, ',') as taille_commande
      from dbo.commande
      group by code_commande, code_article


      STRING_AGG reference



      Note this is only available in SQL Server 2017+ and azure. To see a possible solution for previous versions, see this duplicate.






      share|improve this answer

























        0












        0








        0







        As mentioned, STRING_AGG() is your friend for this requirement. Assuming your original post contained the schema you're working with, a simple aggregate query will give you the results you want.



        select code_commande, code_article, STRING_AGG(taille, ',') as taille_commande
        from dbo.commande
        group by code_commande, code_article


        STRING_AGG reference



        Note this is only available in SQL Server 2017+ and azure. To see a possible solution for previous versions, see this duplicate.






        share|improve this answer













        As mentioned, STRING_AGG() is your friend for this requirement. Assuming your original post contained the schema you're working with, a simple aggregate query will give you the results you want.



        select code_commande, code_article, STRING_AGG(taille, ',') as taille_commande
        from dbo.commande
        group by code_commande, code_article


        STRING_AGG reference



        Note this is only available in SQL Server 2017+ and azure. To see a possible solution for previous versions, see this duplicate.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 2:11









        Tassie DevilTassie Devil

        11 silver badge1 bronze badge




        11 silver badge1 bronze badge
















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55353275%2fconcatenate-rows-for-many-conditions%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현