Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SSMS QUERY

$
0
0

hi ALL,

This is my table:-

Id     Location    Date      Quantity    Starting stck     Ending Stck
1       Delhi    1/1/2013      5
2       Delhi    1/1/2013      7
3       Delhi    1/1/2013      3
4       Delhi    2/1/2013      4
5       Delhi    2/1/2013      7
6       Delhi    2/1/2013      2
7       Delhi    3/1/2013      3
8       Delhi    3/1/2013      4
9       Delhi    4/1/2013      1
10      Delhi    4/1/2013      4
11      Mumbai   1/1/2013      5
12      Mumbai   1/1/2013      7
13      Mumbai   1/1/2013      3
14      Mumbai   2/1/2013      4
15      Mumbai   2/1/2013      7
16      Mumbai   2/1/2013      2
17      Mumbai   3/1/2013      3
18      Mumbai   3/1/2013      4
19      Mumbai   4/1/2013      1
20      Mumbai   4/1/2013      4


I want to calculate the Starting stock and Ending stock based on Starting and ending date..


example:-
staring date =2/1/2013
ending date=4/1/2013


so my starting stock = total Quantity of previous date(i.e 5+7+3=15)[Of same Location only]

Ending stock =sum of Quantity from start to end date(i.e 4+7+2+3+4+1+4=25)[Of same Location only]

Note:Here staring and ending date are dynamically.


thanks

Gs


Viewing all articles
Browse latest Browse all 23857

Trending Articles