Splitting Rows into Two columns and getting sum RRS feed

  • Question

  • User562966027 posted

    I have three tables Lab, Payments and Transaction

    enter image description here

    I want to spilt transType into two columns, sum TransType Group By BillId and compare it with Lab.TotalBill to get Refundable Payments/Due payments I need SQL Query or LINQ Query please

    Monday, December 12, 2016 7:03 AM

All replies

  • User-1838255255 posted

    Hi Qasimali84,

    According to your description, as far as I know, you can use SQL pivot method. it can convert column to row or reserve.  You can refer to this article of how to use pivot:

    Using PIVOT and UNPIVOT:


    Also I use a sample show how to convert week value to column and get the sum of xCount, you can refer to this sample:

    Original select:
    select * from #yt;
    Pivot select:
    select *
      select store, week, xCount
      from #yt
    ) src
      for week in ([1], [2], [3])
    ) piv;


    Best Regards,

    Eric Du

    Tuesday, December 20, 2016 8:49 AM