Recursive Query that involve computation?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Recursive Query that involve computation?

  1. #1
    Nianz Guest

    Recursive Query that involve computation?


    hi to all!

    is this posible in Recursive Query that involve computation?
    or is there other way using Query or T-SQL? to solve my
    problem?


    TrxNo SalesmanID Commission KickBack
    1 S1 500 0
    2 S2 200 0
    3 S1 100 0
    4 S1 100 0
    5 S2 200 0
    6 S2 0 300
    7 S1 0 250

    Here's the story, in every Transaction, a salesman can get Commission(+)
    and KickBack (-).
    the rules is when never a salesman gets a kickback it should deduct thru
    the commission (e.g. Commission - KickBack ).

    so have to create a query that will have additonal field as Deduction.

    TrxNo SalesmanID Commission KickBack | Deduction
    1 S1 500 0 | 50---------> 50
    2 S2 200 0 ---| 200
    3 S1 100 0 | | 100 --------> 100
    4 S1 100 0 | | 100 --------> 100
    5 S2 200 0 | | 0 -----
    6 S2 0 200 <| | 0 250 --
    7 S1 0 250 | 0 |
    ^----------------------------


    Getting the deduction it should compute thru Commission on a LIFO process



    Thankz!
    Nianz


  2. #2
    Michael Levy Guest

    Re: Recursive Query that involve computation?

    You could unroll the recursion using a stack. It won't be the fastest thing
    in the world but the work will get done. I don't understand the calculations
    that you're making but if you can write the calculations recursivly, it can
    be unrolled to a stack.

    -Mike
    --
    Michael Levy MCDBA, MCSD, MCT
    michaell@gasullivan.com



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center