SQL Row aggregation [duplicate]












0















This question already has an answer here:




  • Comma separated results in SQL

    3 answers




Sample data:



Id  User    Value
1 A X=1
1 A Y=2
1 A X=1
1 A X=1
1 A Y=2
1 A X=1
1 A Y=2
1 A X=0
1 A NULL
1 A NULL


I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....



i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.










share|improve this question













marked as duplicate by Larnu, Martin Smith sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 11 at 17:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















    0















    This question already has an answer here:




    • Comma separated results in SQL

      3 answers




    Sample data:



    Id  User    Value
    1 A X=1
    1 A Y=2
    1 A X=1
    1 A X=1
    1 A Y=2
    1 A X=1
    1 A Y=2
    1 A X=0
    1 A NULL
    1 A NULL


    I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....



    i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.










    share|improve this question













    marked as duplicate by Larnu, Martin Smith sql-server
    Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 11 at 17:40


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















      0












      0








      0








      This question already has an answer here:




      • Comma separated results in SQL

        3 answers




      Sample data:



      Id  User    Value
      1 A X=1
      1 A Y=2
      1 A X=1
      1 A X=1
      1 A Y=2
      1 A X=1
      1 A Y=2
      1 A X=0
      1 A NULL
      1 A NULL


      I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....



      i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.










      share|improve this question














      This question already has an answer here:




      • Comma separated results in SQL

        3 answers




      Sample data:



      Id  User    Value
      1 A X=1
      1 A Y=2
      1 A X=1
      1 A X=1
      1 A Y=2
      1 A X=1
      1 A Y=2
      1 A X=0
      1 A NULL
      1 A NULL


      I have a dataset as described in Picture I want to group them based on Id,User each value seperated by 'OR'. for E.g (X=1) OR (Y=2) OR .....



      i found i can use string_agg() but it is available only in sql server 17 but i am using sql server 2014. Any Help would be appreciated.





      This question already has an answer here:




      • Comma separated results in SQL

        3 answers








      sql-server






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 17:22









      Srini

      134




      134




      marked as duplicate by Larnu, Martin Smith sql-server
      Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 11 at 17:40


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Larnu, Martin Smith sql-server
      Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 11 at 17:40


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can do like



          SELECT ID,
          [User],
          STUFF(
          (
          SELECT ' OR ' + '(' + Value + ')'
          FROM T T2
          WHERE T2.ID = T1.ID
          FOR XML PATH('')
          ), 1, 4, ''
          ) Result
          FROM T T1
          GROUP BY ID, [User];





          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can do like



            SELECT ID,
            [User],
            STUFF(
            (
            SELECT ' OR ' + '(' + Value + ')'
            FROM T T2
            WHERE T2.ID = T1.ID
            FOR XML PATH('')
            ), 1, 4, ''
            ) Result
            FROM T T1
            GROUP BY ID, [User];





            share|improve this answer


























              0














              You can do like



              SELECT ID,
              [User],
              STUFF(
              (
              SELECT ' OR ' + '(' + Value + ')'
              FROM T T2
              WHERE T2.ID = T1.ID
              FOR XML PATH('')
              ), 1, 4, ''
              ) Result
              FROM T T1
              GROUP BY ID, [User];





              share|improve this answer
























                0












                0








                0






                You can do like



                SELECT ID,
                [User],
                STUFF(
                (
                SELECT ' OR ' + '(' + Value + ')'
                FROM T T2
                WHERE T2.ID = T1.ID
                FOR XML PATH('')
                ), 1, 4, ''
                ) Result
                FROM T T1
                GROUP BY ID, [User];





                share|improve this answer












                You can do like



                SELECT ID,
                [User],
                STUFF(
                (
                SELECT ' OR ' + '(' + Value + ')'
                FROM T T2
                WHERE T2.ID = T1.ID
                FOR XML PATH('')
                ), 1, 4, ''
                ) Result
                FROM T T1
                GROUP BY ID, [User];






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 17:38









                Sami

                7,32931039




                7,32931039















                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()