Sql Calculation And Sort By Date

Posted by mahesh on Stack Overflow See other posts from Stack Overflow or by mahesh
Published on 2011-02-03T17:00:59Z Indexed on 2011/02/04 7:25 UTC
Read the original article Hit count: 279

Filed under:
|
|
|

I have Confusion against utilize If,Else Statement against calculation of stock By date. And sort the same by date.

There is real challenge to calculate running total between equal date:

  1. If date is equal
  2. If date is greater than
  3. If date is less than

My Table Schema Is:

TransID     int,        Auto Increment

Date       datetime,
Inwards decimal(12,2)
Outward decimal(12,2)

Suppose If I have Records as Below:

TransID Date(DD/MM/YYYY)  Inward        Outward     

1       03/02/2011                        100                                       
2       12/04/2010                        200               
3       03/02/2011          400                          

Than Result Should be:

    TransID Date(DD/MM/YYYY)    Inward  Outward        Balance

    1         03/02/2011                      100         -100                                  
    2         12/04/2010                      200         -300          
    3         03/02/2011            400                    100           

I wants to calculate Inward - outwards = Balance and Balance count as running total as above. but the condition that it should be as per date order

How to sort and calculate it by date and transID?

What is transact SQL IN SQL_SERVER-2000**?.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server