locked
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:

    https://msdn.microsoft.com/en-us/library/ms177410.aspx 

    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 *
    from 
    (
      select store, week, xCount
      from #yt
    ) src
    pivot
    (
      sum(xcount)
      for week in ([1], [2], [3])
    ) piv;

    Result:

    Best Regards,

    Eric Du

    Tuesday, December 20, 2016 8:49 AM